How to enable or disable an anchor using jQuery?
To prevent an anchor from following the specified href, I would suggest using preventDefault():
href
preventDefault()
// jQuery 1.7+ $(function () { $('a.something').on("click", function (e) { e.preventDefault(); }); }); // jQuery < 1.7 $(function () { $('a.something').click(function (e) { e.preventDefault(); }); // or $('a.something').bind("click", function (e) { e.preventDefault(); }); });
See:
http://docs.jquery.com/Events/jQuery.Event#event.preventDefault.28.29
Also see this previous question on SO:
jQuery disable a link
2.1m questions
2.1m answers
60 comments
57.0k users