Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

jQuery off() Method

❮ 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

Try it Yourself - Examples

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

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.