Is there a "global" unbind function in jQuery, such that I'd be able to remove all bound events from a given namespace? eg:
// assume these are the events bound to different elements $('#foo').bind('click.myNS', ...); $('#bar').bind('keyup.myNS', ...); $('#baz').bind('dblclick.myNS', ...); // magic occurs here... $.magicalGlobalUnbindFunction('.myNS'); // ...and afterwards, the three binds from above are gone
All the examples I've seen for unbind require some elements to be selected first. I guess that technically, you could do $('*').unbind('.myNS')
, but that seems very inefficient.
jQuery unbind() Method The unbind() method removes event handlers from selected elements. This method can remove all or selected event handlers, or stop specified functions from running when the event occurs. This method can also unbind event handlers using an event object.
jQuery bind() function is used to attach an event handler to elements, while the unbind() is used to detached an existing event handler from elements.
You could add myNS
as a class to each of the elements where you want to unbind the events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With