jQuery Tutorial Tutorials - jQuery .off() method

jQuery .off() method

The .off() method in jQuery is used to remove the event handlers from the matched elements.

jQuery .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()

jQuery .off() method with Examples

example

Remove all event handlers from all paragraphs:

$( "p" ).off();

Try now

example

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 );

Try now

Date:2019-08-29 23:43:06 From:www.Lautturi.com author:Lautturi