undelegate() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:undelegate

Description

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

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

Syntax

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

The following code shows how to Remove all event handlers added with the delegate() method from all elements:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("body").delegate("p", "click", function(){
        $(this).slideToggle();//from w w  w .  ja v  a 2 s  .c  o m
    });
    $("button").click(function(){
        $("body").undelegate();
    });
});
</script>
</head>
<body>

<button>Remove event handlers</button>

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



</body>
</html>

Related Tutorials