jQuery Tutorial Tutorials - jQuery .unbind() method

jQuery .unbind() method

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

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

jQuery .unbind() method Example

example

removes all handlers attached to the elements

$( "#foo" ).unbind();

example

removes the handlers by specifying the event type

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

example

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

example

Remove a event handler using the Event Object

var count = 0;
$( "#container" ).bind( "click", function( event ) {
  count++;
  if ( count >= 5 ) {
    $( this ).unbind( event );
  }
});
Date:2019-08-29 23:55:08 From:www.Lautturi.com author:Lautturi