.undelegate() methodThe .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.
.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. |
.undelegate() method Exampleunbinds all delegated events from all paragraphs
$("p").undelegate();
unbinds all delegated events by specifying an event type
$( "p").undelegate( "click" );
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 );
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" );
