title: create array of <li>s in a specific div using javascript
body: <p>I'm trying to create an array of <code>&lt;li&gt;</code> that are in a div. So I have</p>
  
  <pre><code>var arr = document.getElementById('mainNav').getElementsByTagName('li');
  </code></pre>
  
  <p>For testing purposes, I put an <code>alert("test"); alert(arr.length);</code> to see if an alert will pop up and what the size of the array is. Neither of the alerts showed up, but if I place an alert before that variable declaration, it works fine. What could be going wrong?</p>