I have an anchor tag that has a jQuery click event linked to it.
The first thing this click event does is to set the anchor as disabled, by setting the disabled attribute to true. This fires the correct look, since it picks up the myAnchor[disabled] style from my stylesheet.
However, it does not stop the Click event from being fired more times while the anchor has disabled set to true. I guess this is because the disabled attribute only works on inputs an not on anchors (as I found out after trying this).
This code is general for many anchors inside the application, so adding some code to the Click event itself is not desirable as I will have to copy this to all the Click methods. Even if I create a function with the required code, it means I (or worse, other developers that might not be aware) will have to remember to put this line first in all Click methods.
Remember that the anchor will probably be enabled at some point again also, so I can't just remove the click event since then when enabling I need to keep track of the function somewhere else as well in addition to the click method.
So the question is, what is the correct way of disabling an anchor?
You can do any of the following.
$('a').click(function() { return false; });
$('a').off('click');
$("a").unbind("click");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With