title: Uncaught TypeError: Cannot read property 'getElementsByTagName' of null
body: <p>I'm trying to select elements with <code>.getElementsByTagName()</code>. </p>
  
  <pre><code>var tags = document.body.getElementsByTagName("*");
  </code></pre>
  
  <p>Current attempt using lessons learned from an existing answer <a href="https://stackoverflow.com/a/7410966/2007055">https://stackoverflow.com/questions/7410949/javascript-document-getelementsbyclassname-compatibility-with-ie/7410966#7410966</a> </p>
  
  <p>But my attempt failed and I have this error:</p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'getElementsByTagName' of null
  </code></pre>
  
  <p>Why is it producing this error and how can I fix it?</p>