No, I think you should be OK. Generally when working with a Javascript that modifies the page you want to wait until all the elements are loaded before trying to do anything:
For example if your script tried to do
before the browser had downloaded the part of the document that contained the element 'mainleft' - you'd get errors because document.getElementById("mainleft") wouldn't return any useful value.Code:document.getElementById("mainleft").style.width = (window.innerWidth-800)/2 + "px";
ihoss used a function which is called from the onload event handler on the body element to do this. It's generally a little "cleaner" to do it this way - you can keep your script separate from the HTML - but with simple scripts just placing them in the source after the elements they need to work with (as you have done) should be fine - if the browser has reached your script in the source it must've already seen the part where the elements were created.
Side note....
Actually, placing the script in the HTML actually does have one slight advantage too - the onload event waits until all elements in the page have been loaded (images and so on) so if you have lots of big images in the page using onload you might have to wait a while before the Javascript is run. Hence there could be a bit of a delay before the script corrects the column widths. Some modern browsers (e.g. Firefox and Opera) provide a DOMContentLoaded event which solves this problem very nicely but it's not supported everywhere.




Reply With Quote