+ 1
is there a way to off all possible events of a specific element without knowing the used events?
5 Respostas
+ 1
try it, you can write a code with this.
.... and yes it is enough... I wrote this
+ 1
Shadi Namrouti
Do you want to remove every binding from your page you can call
$(document).add('*').off();
or specially for the body
$("body").find("*").each(function() {
$(this).off();
});
Do you want to unbind a specially element without knowing the tag, id, class, namespaces or where it is like div, p, ....?
+ 1
asa22 I updated the question.
+ 1
Shadi Namrouti
for example you have a div tag with id=div1,
with $("#div1").off() you removes event handlers from only the #div1 element itself.
if you have some paragraph or img or input inside the div you can remove all event handlers with this
$("#div1").find("*").off();
+ 1
asa22 , my original question is: does $("#div1").off() removes all events bound to #div1 without specifying an event name as a parameter for the off() function for each event? It seems the answer is yes.
For example: using $("#div1").off() is enough.
No need to write:
$("#div1").off("click");
$("#div1").off("mouseOver");
$("#div1").off("keyUp");
...etc.