Count up with delay via setInterval() - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window setInterval

Description

Count up with delay via setInterval()

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 ww  . j  a va  2s .  c o  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