How to change the href for a hyperlink using JQuery

If you want to change href attribute value using JQuery, you can either user attr or prop functions 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", "");

If you are using JQuery 1.6 or above then use prop function 

$("a").prop("href", "");

The difference between prop and attr is that attr grabs the HTML attribute where as prop grabs the DOM property.



About author

User avatar

Waqas Anwar

Founder of, Senior Consultant, Microsoft .NET and Web Technologies