using javascript setTimeout to see if div has loaded
Posted
by Matt
on Stack Overflow
See other posts from Stack Overflow
or by Matt
Published on 2010-04-21T06:19:45Z
Indexed on
2010/04/21
6:23 UTC
Read the original article
Hit count: 262
I'm loading remote data using dynamic script tags and JSON. the remote page that I'm displaying on my website has a div in it that I use to load content into.
The problem is the javascript functions do not see the div as the page loads because it is remote data. if I set a timeout of about 300 it usually works and my javascipt can see the div. But sometimes it takes longer and it breaks the javascript.
I'm tring this:
function load_content()
{
if(document.getElementById('remote_div')==null)
{
setTimeout('load_content()', 300);
}
else
{
document.getElementById('remote_div').innerHTML = 'Content goes here'
}
}
but it just doesn't seem to work... what is wrong with it?
© Stack Overflow or respective owner