unbind() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:unbind

Description

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

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

Syntax

$(selector).unbind(event,function,eventObj);
Parameter Require Description
event Optional. one or more events to remove from the elements.
function Optional. name of the function to unbind
eventObj Optional. event object to remove to use.

The following code shows how to Remove all event handlers for all <p> 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(){
    $("p").click(function(){
        $(this).slideToggle();/*www. ja  v a 2  s.c  o m*/
    });
    $("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>

Related Tutorials