jQuery off() remove click event handler

Description

jQuery off() remove click event handler

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*from   ww w .  j  ava2  s . com*/
<script>
function changeSize() {
  $(this).animate({fontSize: "+=3px"});
}

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

$(document).ready(function(){
  $("body").on("click", "p", changeSize);
  $("body").on("click", "p", changeSpacing);
  $("button").click(function(){
    $("body").off("click", "p");
  });
});
</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 all click event handlers</button>

</body>
</html>



PreviousNext

Related