i'm having a problem when recursion function.i'm get the error in firebug
too much recursion
this is my javascript code:
var contentPc = "list";
waitForBody(contentPc);
function waitForBody(id){
var ele = document.getElementById(id);
if(!ele){
window.setTimeout(waitForBody(contentPc), 100);
}
else{
//something function
}
}
how i can fix this? thanks for your answer.
i'm having a problem when recursion function.i'm get the error in firebug
too much recursion
this is my javascript code:
var contentPc = "list";
waitForBody(contentPc);
function waitForBody(id){
var ele = document.getElementById(id);
if(!ele){
window.setTimeout(waitForBody(contentPc), 100);
}
else{
//something function
}
}
how i can fix this? thanks for your answer.
Share Improve this question asked Nov 23, 2011 at 7:06 viyancsviyancs 2,3394 gold badges40 silver badges72 bronze badges1 Answer
Reset to default 10Presumably, you don't have an id="list"
element in your DOM. That would mean that your initial waitForBody
call would end up here:
window.setTimeout(waitForBody(contentPc), 100);
and that will call waitForBody(contentPc)
while building the argument list for setTimeout
. And then you end up back at the setTimeout
call again but one more stack level deep. I think you mean to say this:
window.setTimeout(function() { waitForBody(contentPc) }, 100);
so that the next waitForBody
call is delayed a little bit.