.unbind()
methodThe .unbind()
method in jQuery is used to remove an event handler from the elements that previously attached to element using .on()
,.bin()
or other method such as .click()
.
.unbind()
method Syntax.unbind(eventType[,handler])
Parameter | Type | Description |
---|---|---|
eventType |
String | JavaScript event type,such as click ,submit . |
handler |
Function | The handler function that is no longer executed. |
.unbind()
method Exampleremoves all handlers attached to the elements
$( "#foo" ).unbind();
removes the handlers by specifying the event type
$( "p").unbind( "click" );
unbind a specified handler, The handler must be a naming function.
var myHandler = function(event) { // code to handle the event }; $( "#foo" ).bind( "click", myHandler ); $( "#foo" ).unbind( "click", myHandler );
Remove a event handler using the Event Object
var count = 0; $( "#container" ).bind( "click", function( event ) { count++; if ( count >= 5 ) { $( this ).unbind( event ); } });