Easy Tutorial
❮ Eff Toggle Sel Input Submit ❯

jQuery off() Method

jQuery Event Methods

Example

Remove the click event from all <p> elements:

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

Definition and Usage

The off() method is typically used to remove event handlers that were added with the on() method.

Since jQuery version 1.7, the off() method is the new replacement for the unbind(), die(), and undelegate() methods. This method brings a lot of convenience to the API and simplifies the jQuery codebase. We recommend using this method.

Note: To remove a specific event handler, the selector string must match the parameters passed to the on() method when the event handler was added.

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


Syntax

Parameter Description
event Required. Specifies one or more events or namespaces to remove from the selected elements. <br> <br>Multiple event values are separated by spaces. Must be valid events.
selector Optional. Specifies the selector that was initially passed to the on() method when adding the event handler.
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 events to add to the elements, and functions to run when the events occur.

More Examples

Replace unbind() with off()

Replace undelegate() with off()

Replace die() with off()

Remove all click event handlers added with on()

Remove a specific event function added with on()

Remove event handlers using the event object


jQuery Event Methods

❮ Eff Toggle Sel Input Submit ❯