Yes, inline JavaScript runs during HTML parsing.
This is safe if you are not trying to get a reference to a DOM element that has not yet been parsed (i.e., any element after the script block in the HTML HTML). You can also refer to any variable defined on early script blocks (if there are any in the scope).
And, as Matt Brown noted in his comment, it is generally not recommended to use the DOMContentLoaded listener (either the oldIE or window.onload workaround) if you place your script that relies on the DOM loaded correctly before the closing </body> . At this point, all HTML elements will be in the DOM already (if you do not have additional elements after </body> , which would be incorrect HTML).
bfavaretto
source share