jQuery undelegate()

Introduction

Remove all event handlers added with the delegate() method from all elements:

Click any p element to make it disappear.

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 ww w.  jav  a2 s  .com*/
<script>
$(document).ready(function(){
  $("body").delegate("p", "click", function(){
    $(this).slideToggle();
  });
  $("button").click(function(){
    $("body").undelegate();
  });
});
</script>
</head>
<body>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>test</button>

</body>
</html>

The undelegate() method was deprecated in version 3.0. Use the on() method instead.

The undelegate() method removes event handlers added with the delegate() method.

$(selector).undelegate(selector,event,function)
Parameter Optional Description
selector Optional. the selector to remove event handlers from
event Optional. one or more event types to remove
function Optional.event handler function to remove



PreviousNext

Related