+ 1

is there a way to off all possible events of a specific element without knowing the used events?

22nd Jan 2019, 11:23 AM
Shadi Alnamrouti
Shadi Alnamrouti - avatar
5 Answers
+ 1
try it, you can write a code with this. .... and yes it is enough... I wrote this
26th Jan 2019, 6:19 PM
asa22
+ 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, ....?
23rd Jan 2019, 5:48 AM
asa22
+ 1
asa22 I updated the question.
25th Jan 2019, 7:58 PM
Shadi Alnamrouti
Shadi Alnamrouti - avatar
+ 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();
26th Jan 2019, 4:00 PM
asa22
+ 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.
26th Jan 2019, 4:53 PM
Shadi Alnamrouti
Shadi Alnamrouti - avatar