title: Cheerio: Loop through children and call html()
body: <p>I have the following HTML which has been passed into Cheerio:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;h1 id=&quot;heading1&quot;&gt;heading1&lt;/h1&gt;
  &lt;p&gt;text&lt;/p&gt;
  </code></pre>
  <p>The output of $.root().html() is this:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;h1 id=&quot;heading1&quot;&gt;heading1&lt;/h1&gt;
  &lt;p&gt;text&lt;/p&gt;
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  <p>I need to loop through the children of body and call .html() on each non-h1 child, and do something else with each h1 child.</p>
  <p>It's important that I loop through the elements in order, I can't select all non-h1 children of body and .html() them all at once.</p>
  <p>I've tried this:</p>
  <pre class="lang-js prettyprint-override"><code>var children = $(&quot;body&quot;).first().children();
  for(var i = 0; i &lt; children.length; i++){
      console.log(children[i].html()); // children[i].html() is not a function
  }
  </code></pre>
  <p>but I can't call .html() after selecting a child from the array. .html() is also not a function when using children.each.</p>
  <p>.html() is a function if instead of getting the element from the array using [i] I use .first(), but obviously this only works for the first element.</p>