title: Getting Child Elements in Javascript
body: <p>How to get the child elements in HTML using JavaScript?</p>
  
  <p>Program:</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(){
    var child = document.getElementById("row");
    var i;
    $("#subpage").html(child.childNodes.length);
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;table&gt;
    &lt;tr id="row"&gt;
      &lt;td&gt; This is td &lt;/td&gt;
      &lt;td&gt; This is td2 &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;div id="subpage"&gt; &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I expect the above program will print output as "2". But it gives "5". The element which contains id as "row" have 2 elements which is
  td. But it gives "5". So how "5" is printed ?</p>
  
  <p>Output:</p>
  
  <pre><code>This is td  This is td2
  5
  </code></pre>