jQuery unbind()

Introduction

Remove all event handlers for all <p> elements:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>//from   www.  j a  va  2s .c o  m
<script>
$(document).ready(function(){
  $("p").click(function(){
    $(this).slideToggle();
  });
  $("button").click(function(){
    $("p").unbind();
  });
});
</script>
</head>
<body>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<p>Click any p element to make it disappear.</p>

<button>Remove all event handlers for all p elements</button>

</body>
</html>

The unbind() method was deprecated in version 3.0. Use the off() method instead.

The unbind() method removes event handlers from selected elements.

If no parameters are specified, the unbind() method will remove all event handlers.

The unbind() method works on any event handler attached with jQuery.

$(selector).unbind(event,function,event_Obj)
Parameter
Optional
Description
event

Optional.

one or more events to remove from the elements.
Multiple event values are separated by space.
function
Optional.
the name of the function to unbind from the specified event for the element
event_Obj

Optional.

the event object to remove to use.
The event_Obj parameter comes from the event binding function



PreviousNext

Related