jQuery unbind()
The unbind()
method in jQuery is used to remove an existing event handler from one or more selected elements. It is the opposite of the bind()
method, which is used to attach new event handlers to elements.
Syntax
The basic syntax of the unbind()
method is as follows:
$(selector).unbind(event, handler);
Where:
selector
: the element(s) you want to remove the event handler from.event
: the type of event to unbind (e.g., "click", "mouseenter", "submit", etc.).handler
: the function that was bound to the event handler, which will be removed.
Use
The unbind()
method is useful when you want to remove an event handler from an element, either because you no longer need it or because you want to replace it with a different one. It can be used with any type of event that has been bound to an element using the bind()
or on()
methods.
Example
Here's an example that demonstrates how to use the unbind()
method to remove a click event handler from a button: