Remove event based on event count - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:off

Description

Remove event based on event count

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>
$(document).ready(function(){
    var x = 0;/*from  www .j a  v  a  2s. com*/
    $("p").click(function(event){
        $("p").animate({fontSize: "+=5px"
    });
    x++;
    if (x >= 2) {
        $(this).off(event);
    }
    });
});
</script>
</head>
<body>

<p>Click this p element to increase its size. The size can only be increased 2 times.</p>

</body>
</html>

Related Tutorials