JavaScript setInterval() Method

JavaScript setInterval() method either call a function evaluates an expression at specified number of milliseconds. This method continues to call/evaluate the expression until window is called. Another way to stop this method is by calling clearInterval() method. Below is a working demo of this useful method.

Hit start..


     This method is very handy on requirement of executing an action over over again. The below example script illustrates the setInterval() method. It takes a function with one second delay, in this case its 1000 millisecond. 
     var dateId4AutoGen;
     function autoGenerateDt() {
         var dateAuto = new Date();
         document.getElementById("datePnlAuto").innerHTML = dateAuto;
     }
     function autoDtSrt() {
         if (dateId4AutoGen) {
             clearInterval(dateId4AutoGen);
         }
         dateId4AutoGen = setInterval(function () {
             autoGenerateDt();
         }, 1000);
     };

No comments:

Post a Comment

Grab The Button...

Grab the above button and add to your blog or website to get easy access to Virtual Species. Simply click the textbox, copy the code and paste where you want to see the button. That's it!