Is there any way to call a function periodically in JavaScript?
You want setInterval()
:
var intervalID = setInterval(function(){alert("Interval reached");}, 5000);
The first parameter to setInterval() can also be a string of code to be evaluated.
You can clear a periodic function with:
clearInterval(intervalID);