Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery unbind events bound with one()

Is there any method to unbind an event that has been bound with one()? Sort of like unone()

like image 877
Chaim Avatar asked Aug 25 '11 18:08

Chaim


People also ask

How do you unbind an event?

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.

What is bind and unbind in jQuery?

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.

Which event is removed in jQuery?

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.

Which method is used to cancel outgoing network request are remove all event listeners associated with the component?

componentWillUnmount() Here you can cancel any outgoing network requests, or remove all event listeners associated with the component.


1 Answers

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);
}
like image 149
Eduard Luca Avatar answered Oct 10 '22 18:10

Eduard Luca