I'm curious what situations exactly require the use of jquery's $(document).ready() or prototype's dom:loaded or any other variant of a handler for this event.
In all the browsers i've tested, it's entirely acceptable to begin interacting with html elements and the DOM immediately after the closing tag. (e.g.
<div id="myID">
My Div
</div>
<script type="text/javascript">
$('#myID').initializeElement();
</script>
So at this point i'm wondering whether $(document).ready()
is merely there to reduce the thinking involved in writing javascript code that runs during page load. In the case of using $(document).ready()
there is regularly rendering issues such as popping and 'artifacts' between the browser first starting to draw the page and the javascript actually executing when the page is 'ready'.
Are there any scenarios where $(document).ready()
is required?
Are there any reasons I shouldn't be writing initialization scripts as demonstrated?