I have a <span>
element which does something on a click event.
When I disable it, using jQuery:
$("span").attr("disabled", true);
The event handler continues to be called when I click on the span element.
I am testing in Chrome 13. Any thoughts?
Try unbinding the event.
Here is the fiddle
The
disabled
attribute is not global and is only allowed on form controls. What you could do is set a custom data attribute (perhapsdata-disabled
) and check for that attribute when you handle the click event.The best method is to wrap the span inside a button and disable the button
The disabled attribute's standard behavior only happens for form elements. Try unbinding the event:
There is a dirty trick, what I have used:
I am using bootstrap, so I just added
.disabled
class to the element which I want to disable. Bootstrap handles the rest of the things.Suggestion are heartily welcome towards this.
Adding class on run time:
Try this:
you can enabled those back by