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

jQuery Start / Stop interval


<!DOCTYPE html>
<html>
<head>

<style>.textzzk2{color:red;}</style>

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

   function myInterval(){
      $(".textzzk").toggleClass("textzzk2");
   }interval = (myInterval);

   $("#stopzzk").click(function(){
    clearInterval(interval);
   });

   $("#startzzk").click(function(){
     clearInterval(interval);
     interval = setInterval(myInterval,500);
   });

});
</script>

</head>
<body>

<button id="stopzzk">Stop</button>
<button id="startzzk">Start</button>
<h1 class="textzzk">Start / Stop interval</h1>

</body>
</html>

Categroy:
Front-end , JQuery