Anyone know how to disable a link in jquery WITHOUT using return false;
?
Specifically, what I\'m trying to do is disable the link of an item, performing
If you go the href route, you can save it
To disable:
$('a').each(function(){
$(this).data("href", $(this).attr("href")).removeAttr("href");
});
Then re-enable using:
$('a').each(function(){
$(this).attr("href", $(this).data("href"));
});
In one case I had to do it this way because the click events were already bound somewhere else and I had no control over it.
I know this isn't with jQuery but you can disable a link with some simple css:
a[disabled] {
z-index: -1;
}
the HTML would look like
<a disabled="disabled" href="/start">Take Survey</a>
You can remove click for link by following;
$('#link-id').unbind('click');
You can re-enable link by followings,
$('#link-id').bind('click');
You can not use 'disabled' property for links.
I always use this in jQuery for disabling links
$("form a").attr("disabled", "disabled");
html link example:
<!-- boostrap button + fontawesome icon -->
<a class="btn btn-primary" id="BT_Download" target="_blank" href="DownloadDoc?Id=32">
<i class="icon-file-text icon-large"></i>
Download Document
</a>
use this in jQuery
$('#BT_Download').attr('disabled',true);
add this to css :
a[disabled="disabled"] {
pointer-events: none;
}