jQuery unbind() unbind event by click time

Description

jQuery unbind() unbind event by click time

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>// w  w w.  j  ava2s  . c  om
<script>
$(document).ready(function(){
  let x = 0;
  $("p").click(function(event){
    $("p").animate({fontSize: "+=5px"});
    x++;
    if (x >= 2) {
      $(this).unbind(event);
    }
  });
});
</script>
</head>
<body>

<p style="font-size:20px;">
Click this p element to increase its size. 
The size can only be increased 2 times.</p>

</body>
</html>



PreviousNext

Related