Search w3schools.com:

SHARE THIS PAGE

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



W3Schools Certification

W3Schools' Online Certification

The perfect solution for professionals who need to balance work, family, and career building.

More than 10 000 certificates already issued!

Get Your Certificate »

The HTML Certificate documents your knowledge of HTML.

The HTML5 Certificate documents your knowledge of advanced HTML5.

The CSS Certificate documents your knowledge of advanced CSS.

The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.

The jQuery Certificate documents your knowledge of jQuery.

The XML Certificate documents your knowledge of XML, XML DOM and XSLT.

The ASP Certificate documents your knowledge of ASP, SQL, and ADO.

The PHP Certificate documents your knowledge of PHP and SQL (MySQL).

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]