Is there any method to unbind an event that has been bound with one()? Sort of like unone()
Use the off() method instead. 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.
If a simple event name such as "click" is provided, all events of that type (both direct and delegated) are removed from the elements in the jQuery set.
componentWillUnmount() Here you can cancel any outgoing network requests, or remove all event listeners associated with the component.
Quote from JQuery.com:
You cannot unbind a listener created using
.one()
. If you want to be able to unbind something that has to occur only once but still be able to unbind it before it occurs, you have to use.bind()
Something like:
$("#element").on("click",function(event){
//do stuff here
$(this).off(event);
}
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