0

Can I remove all the event handlers even these handlers are not directly bond to it?

That's say I have a #maincontainer, which has a #player, which has a lot of .card, then I bind a click event handler to #player. Can I remove it from #maincontainer? And if other children or descendants of #maincontainer are bond to some other event handler, I want these handler to be removed, too.

Mohammad
  • 21,175
  • 15
  • 55
  • 84
unicellular
  • 61
  • 3
  • 8
  • 1
    Quick and dirty: `#maincontainer.innerHTML = #maincontainer.innerHTML`. – Teemu Jul 02 '16 at 12:28
  • You could use event delegation and only bind a listener to `#maincontainer` which you don’t need to remove. – Sebastian Simon Jul 02 '16 at 12:29
  • @Teemu How does these tricks work? – unicellular Jul 02 '16 at 12:32
  • That re-creates your HTML. Listeners from old elements are not attached to the new elements, assuming you've not inline listeners nor delegated listeners on the ancestors of `#maincontainer`. – Teemu Jul 02 '16 at 12:34
  • @unicellular The above was actually a joke (it works in very limited conditions though). See http://stackoverflow.com/questions/13945025/jquery-remove-all-event-handlers-inside-element , that probably suits better for your purposes. – Teemu Jul 02 '16 at 12:41

0 Answers0