jQuery Tutorial Tutorials - jQuery .undelegate() method

jQuery .undelegate() method

The .undelegate() method in jQuery is used to remove a handler from the event for all elements which match the current selector,based on a specific set of root elements.

jQuery .undelegate() method Syntax

.undelegate()
.undelegate(selector,eventType)
.undelegate(selector,events)
.undelegate(selector,eventType,handler)
.undelegate(namespace)
Parameter Type Description
selector String A string contains selector expression used to filter the elements.
eventType String JavaScript event type,such as click,submit.
handler Function The handler function that is no longer executed.
events PlainObject An object containing event types and previously bound handler function to unbind.
namespace String A string containing a namespace to unbind all events from.

jQuery .undelegate() method Example

example

unbinds all delegated events from all paragraphs

$("p").undelegate();

example

unbinds all delegated events by specifying an event type

$( "p").undelegate( "click" );

example

unbind a specified delegated event, The handler must be a naming function.

var myHandler = function(event) {
  // code to handle the event
};
$( "body" ).delegate("p", "click", myHandler );
$( "body" ).undelegate("p", "click", myHandler );

example

unbind all delegated events by their namespace:

var foo = function() {
  
};
 
// Delegate events under the ".whatever" namespace
$( "form" ).delegate( ":button", "click.whatever", foo );
 
$( "form" ).delegate( "input[type='text'] ", "keypress.whatever", foo );
 
// Unbind all events delegated under the ".whatever" namespace
$( "form" ).undelegate( ".whatever" );
Date:2019-08-29 23:55:54 From:www.Lautturi.com author:Lautturi