.off() methodThe .off() method in jQuery is used to remove the event handlers from the matched elements.
.off() method Syntax.off(events) .off(events,selector) .off(events,selector,handler) .off(events,handler)
| Parameter | Type | Description |
|---|---|---|
events |
String | A string contain space-separated event types and optional namespaces, or just namespaces,such as click,submit,keydown.myPlugin, or .myPlugin. |
handler |
Function | event handler function previously attached |
selector |
String | A selector which should match the one originally passed to .on() |
.off() method with ExamplesRemove all event handlers from all paragraphs:
$( "p" ).off();
Remove just one previously bound handler by passing it as the third argument:
var myFun = function() {
// event handler
};
// ... Now myFun will be called when paragraphs are clicked ...
$( "body" ).on( "click", "p", myFun );
// ... myFun will no longer be called.
$( "body" ).off( "click", "p", myFun );
