Organizational Research By

Surprising Reserch Topic

whats the easiest way to call a function every 5 seconds in jquery


whats the easiest way to call a function every 5 seconds in jquery  using -'javascript,jquery,jquery-plugins,timer'

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.
    

asked Sep 16, 2015 by deepak07.s
0 votes
8 views



Related Hot Questions

4 Answers

0 votes

you could register an interval on the page using setInterval, ie:

setInterval(function(){ 
    //code goes here that will be run every 5 seconds.    
}, 5000);
answered Sep 16, 2015 by vickeykumar66
0 votes

Both setInterval and setTimeout can work for you (as @Doug Neiner and @John Boker wrote both now point to setInterval).
See here for some more explanation about both to see which suites you most and how to stop each of them.

answered Sep 16, 2015 by rajeshujade
0 votes

Just a little tip for the first answer. If your function is already defined, reference the function but don't call it!!! So don't put any parentheses after the function name. Just like:

my_function(){};
setInterval(my_function,10000);
answered Sep 16, 2015 by girisha
0 votes

The functions mentioned above execute no matter if it has completed in previous invocation or not, this one runs after every x seconds once the execution is complete

// Anonymous
(function Forever(){
    // Do the Thing Here
    setTimeout(Forever,5000);
})();

// Regular function with arguments
function my_func(arg1,arg2){
    // Do The Thing Here
    setTimeout(function(){
         my_func(arg1,arg2);
    },5000); // Adjust the timeout value as you like
}
answered Sep 16, 2015 by santosh soni

...