June 14, 2013
Is there a way to temporarily override all click bindings on an element using jQuery?
Lokesh Suthar’s Question:
event.preventDefault()
will override default event behavior of an element. How can I temporarily override all click bindings and not just default ones?
Or is there a way to save all the click bindings so I can unbind them and use them later?
Simply as this
$("*").on('click', function(e) {
//override
e.stopPropagation(); // To stop event bubbling further
});
To make this work temporarily, you can add a flag like
var override = true;
Now, check this variable before overriding the
$("*").on('click', function() {
if(override) {
//override
e.stopPropagation();
}
});