How to change the href for a hyperlink using JQuery

Waqas Anwar
26 August 2014
3946 Views

You can use either attr or prop function depending upon the version of JQuery you are using. 

If you are using JQuery 1.5 or below then use attr function 
 $("a").attr("href", "http://www.google.com/");
If you are using JQuery 1.6 or above then use prop function 
$("a").prop("href", "http://www.google.com/");
The difference between prop and attr is that attr grabs the HTML attribute where as prop grabs the DOM property.