<a href="gohere.aspx" class="my-link">Click me</a>
I did
$('.my-link').attr('disabled', true);
but it didn't work
Is there an easy way to disable the hyperlink using jquery? Remove href? I would rather not fiddle with href. So if I can do it w/o removing href, that would be great.
You can bind a click handler that returns false:
$('.my-link').click(function () {return false;});
To re-enable it again, unbind the handler:
$('.my-link').unbind('click');
Note that disabled
doesn't work because it is designed for form inputs only.
jQuery has anticipated this already, providing a shortcut as of jQuery 1.4.3:
$('.my-link').bind('click', false);
And to unbind / re-enable:
$('.my-link').unbind('click', false);