title: Get text of nested childnodes javascript
body: <p>Although I have read many posts on this subject, I am unable to get the desired result.<br/>
  My goal is to get text of nested childnodes in pure JavaScript.
  with this code</p>
  
  <pre><code>function GetChildNodes () {
      var container = document.getElementById ("find");
      for (var i = 0; i &lt; container.childNodes.length; i++) {
          var child = container.childNodes[i];
          if (child.nodeType == 3) {
             var str=child.nodeValue
             console.log(str)
          }
          else {
              if (child.nodeType == 1) {
                  var str=child.childNodes[0].nodeValue
                  console.log(str)                        
              }
          }
      }
  }
  
  GetChildNodes()
  </code></pre>
  
  <p>I can get the text if html is</p>
  
  <pre><code>&lt;div id="find"&gt;
      aaa
      &lt;div&gt;aaa&lt;/div&gt;
      &lt;div&gt;aaa&lt;/div&gt;
      &lt;div&gt;aaa&lt;/div&gt;
      &lt;div&gt;aaa&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>But with html code like this</p>
  
  <pre><code>&lt;div id="find"&gt;
      aaa
      &lt;div&gt;aaa&lt;div&gt;bbb&lt;/div&gt;&lt;/div&gt;
      &lt;div&gt;aaa&lt;div&gt;bbb&lt;/div&gt;&lt;/div&gt;
      &lt;div&gt;aaa&lt;/div&gt;
      &lt;div&gt;aaa&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>...is wrong.<br/>
  Could you please give me a solution?</p>