Remove element event handler - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:off

Description

Remove element event handler

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 changeSize() {//from w  w w.  j a  v  a 2  s  .  c o m
    $(this).animate({fontSize: "+=10px"});
}

function changeSpacing() {
    $(this).animate({letterSpacing: "+=5px"});
}

$(document).ready(function(){
    $("p").on("click", changeSize);
    $("p").on("click", changeSpacing);
    $("button").click(function(){
        $("p").off("click", changeSize);
    });
});
</script>
</head>
<body>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<p>Click any p element to increase size and letterspacing.</p>

<button>Remove the changeSize() event handler</button>

</body>
</html>

Related Tutorials