title: Use of document.getElementById in JavaScript
body: <p>Can someone explain what the <code>document.getElementById("demo")</code> line does in the example below?</p>
  
  <p>I understand getElementById gets the id of demo but the id is <code>&lt;p id="demo"&gt;&lt;/p&gt;</code> What exactly is <code>&lt;p id="demo"&gt;&lt;/p&gt;</code> doing in this code?</p>
  
  <p><code>document.getElementById("age")</code> is clear as it gets the id of age which is the input.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function myFunction() {
    var age,voteable;
    age = document.getElementById("age").value;
    voteable = (age &lt; 18)? "Too young" : "Old enough";
    document.getElementById("demo").innerHTML = voteable;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;p&gt;Click the button to check the age.&lt;/p&gt;
  
  Age:&lt;input id="age" value="18" /&gt;
  &lt;p&gt;Old enough to vote?&lt;/p&gt;
  &lt;button onclick="myFunction()"&gt;Try it&lt;/button&gt;
  
  &lt;p id="demo"&gt;&lt;/p&gt;</code></pre>
  </div>
  </div>
  </p>