i can use this code to remove click event,
$('p').unbind('click')
but , has some method to remove all event ?
has a method named unbindAll
in jquery ?
thanks
To remove all event listeners from an element: Use the cloneNode() method to clone the element. Replace the original element with the clone. The cloneNode() method copies the node's attributes and their values, but doesn't copy the event listeners.
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.
As of jQuery 1.7, off()
and on()
are the preferred methods to bind and unbind event handlers.
So to remove all handlers from an element, use this:
$('p').off();
or for specific handlers:
$('p').off('click hover');
And to add or bind event handlers, you can use
$('p').on('click hover', function(e){ console.log('click or hover!'); });
You can call .unbind()
without parameters to do this:
$('p').unbind();
From the docs:
In the simplest case, with no arguments,
.unbind()
removes all handlers attached to the elements.
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