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 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.
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