setTimeout and clearTimeout usage - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window setTimeout

Description

setTimeout and clearTimeout usage

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   ww w.  j ava  2s.  c  o  m
var i=10;
var countDwn;
var dumping = document.getElementById('dump');
function theTime(){
    if(i > 0){
        i-=1;
    }else{
       clearTimeout(countDwn);
    }
    dumping.innerHTML = i;
    countDwn = setTimeout(theTime,1000);
}
theTime();
    });

      </script> 
   </head> 
   <body> 
      <p id="dump"></p>  
   </body>
</html>

Related Tutorials