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
You should find you answer here.
Thanks @Will and @Matt for this elegant solution.
jQuery('#path .to .your a').each(function(){
var $t = jQuery(this);
$t.after($t.text());
$t.remove();
});
Just use $("a").prop("disabled", true);
.
This will really disable de link element.
Needs to be prop("disabled", true)
. Don't use attr("disabled", true)
Just trigger stuff, set some flag, return false. If flag is set - do nothing.
Just set preventDefault and return false
$('#your-identifier').click(function(e) {
e.preventDefault();
return false;
});
This will be disabled link but still, you will see a clickable icon(hand) icon. You can remove that too with below
$('#your-identifier').css('cursor', 'auto');
unbind()
was deprecated in jQuery 3
, use the off()
method instead:
$("a").off("click");
My fav in "checkout to edit an item and prevent -wild wild west clicks to anywhere- while in a checkout" functions
$('a').click(function(e) {
var = $(this).attr('disabled');
if (var === 'disabled') {
e.preventDefault();
}
});
So if i want that all external links in a second action toolbar should be disabled while in the "edit-mode" as described above, i'll add in the edit function
$('#actionToolbar .external').attr('disabled', true);
Link example after fire:
<a href="http://goo.gl" target="elsewhere" class="external" disabled="disabled">Google</a>
And now you CAN use disabled property for links
Cheers!