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!
This is the most obvious way:
var myFunction = function() {
};
myFunction();
setInterval(myFunction, 10000);
Alternatively, use setTimeout():
(function foo() {
// do stuff here
setTimeout(foo, 10000);
})();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With