Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (7k points)

I am using setInterval(fname, 10000); to call a function every 10 seconds using javascript. Is it possible to stop calling it on some event?

I want the user to be able to stop the repeated refresh of data.

1 Answer

0 votes
by (13.1k points)

setInterval() returns a interval ID, which you can pass to clearInterval():

var refreshIntervalId = setInterval(fname, 10000);

/* later */

clearInterval(refreshIntervalId);

If you want more information see the docs of setInterval() and clearInterval()

Want to be a full stack developer? Check out the full stack developer course from Intelipaat.

Browse Categories

...