title: Are IDs for an html element always available from the window object?
body: <p>I noticed the following: </p>
  
  <pre><code>&lt;div id='myDiv'&gt;...&lt;/div&gt;
  
  &lt;script&gt;
      myDiv.style.color = 'red'; // I can access the object.
  &lt;script&gt;
  </code></pre>
  
  <p>Before realizing this, I was always using the following:</p>
  
  <pre><code>var x = document.getElementById('myDiv'); 
  x.style.color = 'red';
  </code></pre>
  
  <p>I am confused. What's the point of the second approach? Does the first approach always work? </p>