jQuery unbind()Method

jQuery 事件方法jQuery Event Methods

Examples

Remove all event handlers of <p> elements:

$("button").click(function(){
$("p").unbind();
});

Try it yourself »

Definition and Usage

The unbind() method removes event handlers from selected elements.

This method can remove all or selected event handlers, or terminate the execution of specified functions when an event occurs.

This method can also use the event object to unbind event handlers. It is also used to unbind events from itself (for example, deleting the event handler after an event has been triggered a certain number of times).

Note:If no parameters are specified, the unbind() method removes all event handlers of the selected elements.

Note:The unbind() method works for any event handler added by jQuery.

As of jQuery version 1.7,on()andoff()the methods are the preferred way to add and remove event handlers on elements.


Syntax

$(selector).unbind(event,function,eventObj)

Parameter Description
event Optional. Specifies one or more events to remove from the element.
Multiple event values are separated by spaces.
If only this parameter is specified, all functions bound to the specified event will be removed.
function Optional. Specifies the name of the function to unbind from the specified event on the element.
eventObj Optional. Specifies the event object to use for removal. This eventObjparameter comes from the event binding function.


实例

More Examples

Unbind a specified function
How to use the unbind() method to unbind a specified function from a specified event on an element.

Use the event object to unbind event handlers
Specifies the event object to be removed.


jQuery 事件方法jQuery Event Methods

Other Extensions