Remove click event handler and its handler function - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:unbind

Description

Remove click event handler and its handler function

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>
function alertMe() {/* w  w w.  j  a va2 s .  c  o  m*/
    console.log("Hello World!");
}

$(document).ready(function(){
    $("p").click(alertMe);
    $("button").click(function(){
        $("p").unbind("click", alertMe);
    });
});
</script>
</head>
<body>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<p>Click any p element to trigger an alert box.</p>

<button>Remove the alert box function from the click event for the p elements</button>

</body>
</html>

Related Tutorials