Javascript is executing as seen. Typically, the browser stops parsing the page as soon as it sees the <script> , loads and runs the script, and then continues to work. This is why it is usually recommended to place <script> tags at the bottom: so the user does not have a blank page while the browser is waiting for scripts to load.
However, starting with Firefox 3.5, scripts load in the background while the rest of the page is displayed. In the unusual case when a script uses document.write or similar, Firefox will update and redraw if necessary. I don’t think that other browsers are doing this at the moment, but I won’t be surprised if this happens, and IE at least supports the defer attribute in the <script> , which defer loading the script until after the page loads.
DOMContentLoaded is exactly what: it starts as soon as the DOM loads. That is, as soon as the browser has analyzed all the HTML code and created its internal tree. It does NOT wait for images, CSS, etc. to load. The DOM is all you usually need to run any Javascript you need, so it's nice not to wait for other resources. However, I believe that only Firefox supports DOMContentLoaded ; in other browsers, ready() simply bind the event to the normal old onload .
Javascript is guaranteed to work in the order in which it appears in your HTML, so just make sure your function is defined before you try to attach it to an event.
Eevee Aug 20 '09 at 18:26 2009-08-20 18:26
source share