Stop thread with count flag - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window setInterval

Description

Stop thread with count flag

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from  w  w  w  .j  av a  2s.  co m
    var i = 0;
    theLabel = document.getElementById("counter");
    var interval = setInterval(function(){
        if (i == 100) 
           clearInterval(interval);
        theLabel.innerHTML = i;
        i++;
    },
    1000);
    }

      </script> 
   </head> 
   <body> 
      <div id="counter"></div>  
   </body>
</html>

Related Tutorials