Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery setInterval execute on page load

Tags:

jquery

Helllo, I have a function that needs to be executed every 10 seconds. It works like this:

setInterval(function () {

}, 10000);

The problem is that I need this function to be executed once on page load - now the first execution happens only after 10 seconds. Is it possible to do what I want with setInterval, or is there another function?

Thank you for your time!

like image 967
user2840278 Avatar asked Feb 14 '26 22:02

user2840278


1 Answers

This is the most obvious way:

var myFunction = function() {

};

myFunction();
setInterval(myFunction, 10000);

Alternatively, use setTimeout():

(function foo() {
    // do stuff here
    setTimeout(foo, 10000);
})();
like image 200
Ja͢ck Avatar answered Feb 16 '26 11:02

Ja͢ck