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.
Presumably, you don’t have an
id="list"element in your DOM. That would mean that your initialwaitForBodycall would end up here:and that will call
waitForBody(contentPc)while building the argument list forsetTimeout. And then you end up back at thesetTimeoutcall again but one more stack level deep. I think you mean to say this:so that the next
waitForBodycall is delayed a little bit.