Q:

Window.onload vs procedural execution

When using procedural style the code seemed to be executing with the wrong width dimensions of an element (i suspect the code was executing before the element was finished being created), when i refreshed the page all was fine. 
Issue:
<html>
    <head></head>
    <body>
        <div id="parent">
        </div>
        <script language="javascript" type="text/javascript">
            create_object(); // Creates an element and puts it inside div parent
        </script>
    </body>
</html>

Solution:
<html>
    <head>
        <script language="javascript" type="text/javascript">
            window.onload = function(){
                create_object(); // Creates an element and puts it inside div parent
            }
        </script>
    </head>
    <body>
        <div id="parent">
        </div>
    </body>
</html>

What is the difference? 
The window.onload waits for the page to load of course but since the  is after the element.. shouldn't that be just fine? 
No other java script is being executed on the page. 

A:

window.onload waits for all page resources (such as images and style sheets) to be loaded before calling its callback.   In your first example, the DOM elements will all exist (because your code is executing at the end of the body after things before it have been parsed), but external resources like images may not yet be loaded and thus final layout may not yet be achieved so everything may not yet have its final size/layout.