ZaZaKi, a web developer Between Manchester UK & Rotterdam NL. © 2015-2024.

jQuery Limited interval


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){

   var count = 0;

   // interval
   function myInterval(){
      // toggle the text  
      $('.zzkBlink').toggle ();

      $("#countDisplay").html(count); count++;

      // stops the interval if condition true
      if(count == 10 ) {    
         //clears the interval
         clearInterval(interval);
      }
   }interval = (myInterval);

   // starts the interval
   $("#start").click(function(){

     // resets the interval
     clearInterval(interval);

     // resets the counts
     count = 0 ;

     // sets the interval
     interval = setInterval(myInterval,200);
   });

});
</script>
</head>
<body>

<button id="start">start</button>
<h1 id="countDisplay"> 0</h1>
<h1 class="zzkBlink">Blinking Text</h1>

</body>
</html>

Categroy:
Front-end , JQuery