title: JavaScript document.getElementById(“id”) and element id attribute
body: <p>I have:</p>
  
  <pre><code>&lt;div id="myDiv1"&gt;&lt;/div&gt;
  &lt;div id="myDiv2"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>In JavaScript, I can set div innerHTML by writing:</p>
  
  <pre><code>myDiv1.innerHTML = "myDiv1, Hi!"
  </code></pre>
  
  <p>or</p>
  
  <pre><code>document.getElementById("myDiv2").innerHTML = "myDiv2, Hi!"
  </code></pre>
  
  <p>Why should I use document.getElementById when I can simply use element Id ? Is this working every time or only in some special scenarios (like simple sample)?</p>
  
  <p>thanks,</p>
  
  <p>Mike</p>