How call JavaScript functions in time interval. I want call a function with time interval how can I done that
Asked
Active
Viewed 65 times
-2
-
1https://duckduckgo.com/?q=javascript+interval – Quentin Jan 14 '18 at 08:15
1 Answers
0
If you want to call it after a certain time interval you can do something like this (this will do it after 3 seconds);
setInterval(MyFunc, 3000);
setInterval()
has a signature that is a function being the first parameter and the interval in milliseconds as the second parameter (thus the amount of seconds is equal to 3000/1000 as there are 1000 milliseconds per second). SetInterval will also call that function over and over again every 3 seconds! So make sure you want it to!
For example if you wanted to show an alert you could do:
setInterval(function() { alert("Hello World") }, 3000);
If you want it to run only once just replace setInterval
with setTimeout
which will just run it once after the time given (again in milliseconds).

Braedon Wooding
- 161
- 11