View Full Version : DOM works without window.onload

09-30-2003, 12:42 AM
This is slightly worrying - I was under the impression that properties of objects in mozilla are not available until the entire document has finished loading; but I just tried out a complex menu script I'm working on, processing the <ul> without window.onload, just ensuring that the initialisation calls happen at the end of the script, which is after the <ul> in the document.

... blah ...


//object constructor

//a few methods

//call object constructor


And it works fine. But I feel worried. Are there circumstances under which it won't work so fluidly, or am I being paranoid for nothing?

09-30-2003, 04:07 AM
Why would you need the page to fully load? The DOM is dynamic, especially so during page rendering. The entire <ul> node has been created in memory by the time your script is executed, so there shouldn't be any issues. Things to be concerned about would be accessing childnodes and siblings during page load, but that is the only thing I'd be concerned about.

09-30-2003, 07:17 AM
Well, the thing is rather that the document is not finished yet, and thus the user agent doesn't necessarily provide getElementById, getElementsByTagName, body or documentElement properties of the document yet. Thus you can't rely on those being present, or if they are present, that they will work as they should. The node you want to handle itself, though, will be present and you can do anything you want with it.