English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The off() method is usually used to remove event handlers added throughon()event handlers added by the method.
Since jQuery version 1.7 The off() method is the new replacement for the unbind(), die(), and undelegate() methods. This method brings many conveniences to the API, and we recommend using this method as it simplifies the jQuery code library.
To attach an event that runs once and then removes itself, useone()Method.
$("selector").off(event, selector, function)
Remove the mousemove event from the document:
$("button").click(function(){ $("document").off("mousemove"); });Test See‹/›
Remove the mousemove event from the DIV element:
$("button").click(function(){ $("div").off("mousemove"); });Test See‹/›
Remove all click event handlers from all <p> elements added using the on() method:
$("button").click(function(){ $("body").off("click", "p"); });Test See‹/›
Remove a specific event function added with the on() method:
$("#btn1").click(function(){ $("p").off("click", changeSize); });Test See‹/›
Remove multiple event handlers from the <div> element:
$("button").click(function(){ $("div").off("mouseenter mouseleave"); });Test See‹/›
Calling off() without parameters will remove all handlers attached to the element:
$("button").click(function(){ $("div").off(); });Test See‹/›
Parameter | Description |
---|---|
event | Specify one or more events or namespaces separated by spaces to remove from the selected element |
selector | Optionally, the selector should match the selector originally passed to the on() method when attaching the event handler |
function | Optionally specify the handler function previously attached to the event |