Call a Javascript function every 5 seconds continuously

deepmoteria picture deepmoteria · Aug 25, 2011 · Viewed 257.6k times · Source

Possible Duplicate:
Calling a function every 60 seconds

I want to Call a Javascript function every 5 seconds continuously. I have seen the setTimeOut event. Will it be working fine if I want it continuously?

Answer

Anantha Sharma picture Anantha Sharma · Aug 25, 2011

You can use setInterval(), the arguments are the same.

const interval = setInterval(function() {
   // method to be executed;
 }, 5000);

clearInterval(interval); // thanks @Luca D'Amico