What’s the easiest way to call a function every 5 seconds in jQuery? [duplicate]

JQuery, how to call a function every 5 seconds.

I’m looking for a way to automate the changing of images in a slideshow.

I’d rather not install any other 3rd party plugins if possible.

7 s
7

You don’t need jquery for this, in plain javascript, the following will work!

var intervalId = window.setInterval(function(){
  /// call your function here
}, 5000);

To stop the loop you can use

clearInterval(intervalId) 

Leave a Comment