Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As far as I know, in HTML <strong>scripts are parsed sequentially</strong> (unless they have defer attribute, but that's another story). </p> <p>If you look at <a href="http://www.w3.org/TR/1999/REC-html401-19991224/interact/scripts.html#h-18.1" rel="nofollow noreferrer">SCRIPT section in HTML4.01 specs</a>, you can see that:</p> <blockquote> <p>Scripts may be evaluated as a document loads to modify the contents of the document dynamically.</p> </blockquote> <p>and that:</p> <blockquote> <p>All SCRIPT elements are evaluated in order as the document is loaded.</p> </blockquote> <p>There's also an example of how the following script would affect resulting markup:</p> <pre><code> &lt;TITLE&gt;Test Document&lt;/TITLE&gt; &lt;SCRIPT type="text/javascript"&gt; document.write("&lt;p&gt;&lt;b&gt;Hello World!&lt;\/b&gt;") &lt;/SCRIPT&gt; </code></pre> <p>Has the same effect as this HTML markup:</p> <pre><code> &lt;TITLE&gt;Test Document&lt;/TITLE&gt; &lt;P&gt;&lt;B&gt;Hello World!&lt;/B&gt;&lt;/P&gt; </code></pre> <p>Since your script is contained right after BODY and has no DEFER attribute, it's probably safe to assume that during script execution, <strong>BODY tag is already parsed and BODY element is already created</strong> (but not the rest of the tree, such as elements created from the markup following script in question!).</p> <p>And, of course, you should really <strong>use faster, more compatible and shorter <code>document.body</code></strong> rather than <code>document.getElementsByTagName('body')[0]</code> :)</p> <p>In fact, I would replace this whole chunk:</p> <pre><code>(function() { var body = document.getElementsByTagName('body'); if ( body &amp;&amp; body[0] ) { body[0].className = body[0].className.replace(/no_javascript/, "javascript"); } })(); </code></pre> <p>with something like:</p> <pre><code>document.body.className = document.body.className.replace('no_javascript', 'javascript'); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload