Replace a URL using jQuery

The problem: I need to replace a url on one page, but that url was defined in the master page of an asp.net app.

The solution: Use the jQuery .attr (attribute) selector to find the matching href attribute I want to replace. Here’s the one line of code that does the trick:

[crayon lang="javascript"]$(“a[href]=’http://mysite.com/old’]”).attr(‘href’, ‘http://mysite.com/new’ )[/crayon]

Result: Mind. Blown. Instant awesomeness without needing to rebuild the app.