title: Using vanilla javascript, add class to body from within head
body: <p>I want to do a quick javascript check from within the <code>head</code> tag, like so:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          ...
          &lt;script&gt;
              document.body.classList.remove("no-js");
              document.body.classList.add("js");
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body class='no-js'&gt;
          ...
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This doesn't work. <code>Cannot read property classList of null</code>, which...fair enough. If I move the <code>&lt;script&gt;</code> tag into <code>&lt;body&gt;</code>, everything works, but I want the <code>&lt;script&gt;</code> tag in <code>&lt;head&gt;</code>.</p>
  
  <p>What are my options?</p>
  
  <p>EDIT: I should have been much clearer about the error. I realize the problem is that body hasn't loaded when I'm trying to to add the class. However, I was using a bit of Modernizr originally and it was somehow able to modify the body class from within the head and I don't <em>think</em> it was using <code>window.onload</code> or anything like that. </p>