How to effectively remove namespaced event listeners from ALL DOM elements?

I know I can do it like this: $('*').off('.namespace');

But my feeling is *

not a good idea because jQuery will go through the whole DOM tree and it will be slow.

jQuerys internal $.cache

contains information about event listeners that have been linked through.on()

Is there a way to tell jQuery to just go through that internal cache and remove all event listeners from a specific namespace from any elements - without the need for *

a DOM tree?

Edit: The problem is that I don't know which elements the listeners were attached to - I only know the namespace they were attached to.

+3


source to share


1 answer


Why not just put a hook on each element as well when binding an event to it?

$('.some_el').addClass('has_foo_event').on('click.foo', function() {});

      



Then

$('.has_foo_event').off('.foo');

      

0


source







All Articles