THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

jQuery off() Method

jQuery Event Methods jQuery Event Methods

Example

Remove the click event for all <p> elements:

$("button").click(function(){
    $("p").off("click");
});
Try it yourself »

Definition and Usage

The off() method is most often used to remove event handlers attached with the on() method.

As of jQuery version 1.7, the off() method is the new replacement for the unbind(), die() and undelegate() methods. This method brings a lot of consistency to the API, and we recommend that you use this method, as it simplifies the jQuery code base. 

Note: To remove specific event handlers, the selector string must match the one passed to the on() method, when the event handler was attached. 

Tip: To attach an event that only runs once and then removes itself, use the one() method.


Syntax

$(selector).off(event,selector,function(eventObj),map)

Parameter Description
event Required. Specifies one or more events or namespaces to remove from the selected element(s).

Multiple event values are separated by a space. Must be a valid event
selector Optional. A selector which should match the one originally passed to the on() method when attaching event handlers
function(eventObj) Optional. Specifies the function to run when the event occurs
map Specifies an event map ({event:function, event:function, ...}) containing one or more event to attach to the elements, and functions to run when the events occur

Examples

Try it Yourself - Examples

Changing from unbind() to off()
How to use off() to achieve the same effect as unbind().

Changing from undelegate() to off()
How to use off() to achieve the same effect as undelegate().

Changing from die() to off()
How to use off() to achieve the same effect as die().

Remove all click event handlers, added with on()
How to remove all click event handlers for all <p> elements added with the on() method.

Remove one specific event function added with on()
How to remove a specific function added with the on() method.

Remove an event handler using an event object
How to remove an event handler after the event has been triggered a certain number of times.


jQuery Event Methods jQuery Event Methods