do I really need to call getElementById()?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/3434278/ie-chrome-are-dom-tree-elements-global-variables-here">IE/Chrome: are DOM tree elements global variables here?</a>  </p>
</blockquote>



<p>I just stumbled upon an unexpected but useful behavior in the browser: It creates a variable for every element that has an ID in my html code. So when I have:</p>

<pre><code>&lt;div id="ohlala"&gt; ... &lt;/div&gt;
</code></pre>

<p>the browser seem to run this code behind the scene:</p>

<pre><code>var ohlala = document.getElementById("ohlala");
</code></pre>

<p>so I can easily change the text of that element by:</p>

<pre><code>ohlala.innerHTML="test"
</code></pre>

<p>Try it online: <a href="http://jsfiddle.net/Facby/" rel="nofollow">http://jsfiddle.net/Facby/</a>
The question is: why would I need to write the <code>document.getElementById()</code> bit myself? How portable is that code? I tried in Opera, FireFox and Chrome and it works! Can I rely on this functionality? Does the browser always create variables for every element with id? In that case I have to be more careful about the names that are used in my javascript code not to conflict with similar ids from the HTML, right?</p>
