Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  171] [ 1]  / answers: 1 / hits: 28237  / 13 Years ago, tue, august 2, 2011, 12:00:00

Can someone quickly and simply explain to me how to perform an action every couple of seconds using



var timeOut = setTimeout(FunctionName, 5000);


I want to run a function every 5 seconds.


More From » javascript

 Answers
48

As you asked for a method using setTimeout:



function doStuff() {
console.log(hello!);
setTimeout(doStuff, 5000);
}
setTimeout(doStuff, 5000);


But it would probably be better to use setInterval:



function doStuff() {
console.log(hello!);
}
setInterval(doStuff, 5000);

[#90869] Sunday, July 31, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jocelynkarsynr

Total Points: 472
Total Questions: 98
Total Answers: 96

Location: Macau
Member since Mon, Nov 16, 2020
4 Years ago
jocelynkarsynr questions
Tue, Feb 8, 22, 00:00, 2 Years ago
Sat, Jul 11, 20, 00:00, 4 Years ago
Sun, May 10, 20, 00:00, 4 Years ago
Sat, Jan 18, 20, 00:00, 4 Years ago
;