Using javascript to check if div exists from injected HTML
<p>For a website I'm working on, I've created an embed function. This is just a call to a javascript on my server that injects some HTML on the remote server. </p>

<p>To make sure the embeds also get some Google juice, I've added a piece of html, so the embed code looks something like this:</p>

<pre><code>&lt;script type="text/javascript" src="http://myserver.com/myscript.js"&gt;&lt;/script&gt;
&lt;div id="embedSource"&gt;Source: &lt;a href="myserver.com"&gt;mysite.com&lt;/a&gt;&lt;/div&gt;
</code></pre>

<p>It's easy to remove the last div with the source in it from the embed code. So I thought I'd just add a little detection script in the first "myscript.js" to detect the presence of the div with id "embedSource".</p>

<p>Problem is: the javascript is always executed first, then the div is being added to the DOM and there is no way that I can add the embedSource div first.</p>

<p>I've tried to check using: </p>

<pre><code>window.onload = CheckIfEmbedCodeIsComplete();
</code></pre>

<p>But this event is fired to early (Chrome, FF and IE). Even though for most browsers it should be enouugh (right?).
Also tried:</p>

<pre><code>setTimeOut(CheckIfEmbedCodeIsComplete(), 5000);
</code></pre>

<p>But again, the check is being called immediately, not after 5 seconds as you would expect.</p>

<p>What can I do to still check if that div exists?</p>
