Quote:
Originally Posted by Raymond Cheyne
I suggestion putting your script in the <head>, not the <body>. Beyond that, sorry, I'm not sure.
Raymond
|
JavaScript belongs at the bottom of the body not in the head. This is particularly true of scripts like this that use document object model commands where the script needs to come AFTER the parts of the HTML that it is referencing.
The only script I know of that needs to go in the head of a web page is the one that tests if the page is about to load inside a frame and which reloads the page outside of the frame. All other scripts run better at the bottom of the page where in most cases you can then remove references to onload and so reduce the chances of script clashes.
Placing scripts in the head was common back in the Netscape 4 days prior to JavaScriptbeing able to properly interact with the HTML. It became far less efficient to put the scripts in the head when the DOM was introduced in more modern browsers such as IE5.