I know what the problem I am experiencing is, I am just having a hard time finding a work around. I was wondering if anyone had experienced something like this, and what kinda of solution they implemented.
I have a list system with pending repairs, and I want repairs that are late to blink black and red. It’s possible that there are multiple repairs in this list that are late.
here is my function:
function setblink(id) {
var elm = document.getElementById(id);
if (elm.color == "red"){
elm.color = "black";
}
else{
elm.color = "red";
}
setTimeout(setblink(id),500);
}
I have an array of “id’s” for the items that need to be blinking called repsToBlink.
I get the set blink intervals running for each of these repairs by running the following code, which puts them in a recursive loop.
for(var x in repsToBlink){
setTimeout(setblink(repsToBlink[x]),500);
}
How can I get this code doing the same thing, without causing a stack overflow?
Thanks!
You need to change your setTimeout from
to:
setTimeout()expects a function to be passed as parameter, whereas you are passing the result of the function.