JQuery load function page loading issue
<p>I have a main.html in which I am trying to load another HTML.
The code in main.html is like this:</p>

<pre><code>&lt;script type="text/javascript"&gt;
$(window).load(function(){
    $("#divid").load("sample.html");
});
&lt;/script&gt;
</code></pre>

<p>Inside the sample.html, I have another JavaScript which doesn't work as expected.</p>

<pre><code>&lt;!-- inside sample.html --&gt;
&lt;script type="text/javascript"&gt;
... Some JavaScript here ...
&lt;/script&gt;
</code></pre>

<p>I do not even get the width of an element correctly. Surprisingly, if I put a breakpoint in the JavaScript or put an alert, all seem to work well. This made me guess that page might not be loaded when script runs and by putting alert or breakpoint gives it a bit more time ? I did some searching on web and think that the loading is not in sync which means that the script inside the sample.html page is executing before the page could load. This is just my guess.
I have tried adding JQuery functions ready and load inside the sample.html as well but nothing changes.
Any idea what could be wrong here ?</p>