Edit This Code:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("p").click(function(){
        $(this).css("background-color", "pink");
    });
    $("#btn1").click(function(){
        $("p").off();
    });
    $("#btn2").click(function(){
        $("p").unbind();
    });
});
</script>
</head>
<body>

<h4 style="color:green;">This example demonstrates how to achieve the same effect using off() and unbind().</h4>

<p>Click this paragraph to change its background color.</p>
<p>Click the button below and then click on this paragraph (the click event is removed).</p>

<button id="btn1">Remove the click event with off()</button>

<button id="btn2">Remove the click event with unbind()</button>

</body>
</html>


Result:
Try it Yourself - © w3schools.com
Privacy Policy