Home Javascript How to set a timer in JavasScript?
 
 
 

How to set a timer in JavasScript?

PDF Print E-mail

Question: How to set a timer in JavaScript?

 

Answer: 

If we want to call a function every 10 seconds using JavaScript we can accomplish it by implementing the following piece of code

window.setInterval('yourfunction()', 1000);
 
function yourfunction(){
alert('test');
}

With the code above every 10 seconds a JavaScript function with the name yourfunction will be called that will prompt an alert.

window.setInterval = Evaluates an expression each time a certain number of seconds have elapsed

+/-
+/- Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
Security Please input the anti-spam code that you can read in the image.
 
 
Banner