title: Wrap Some Child Elements with a Parent Div using Javascript
body: <p>How can I wrap a variable number of child divs with a new parent div in Javascript?  </p>
  
  <pre><code>&lt;div class="child"&gt;1&lt;/div&gt;  
  &lt;div class="child"&gt;2&lt;/div&gt;  
  &lt;div class="child"&gt;3&lt;/div&gt;  
  &lt;div class="child"&gt;4&lt;/div&gt;  
  &lt;div class="child"&gt;5&lt;/div&gt;  
  </code></pre>
  
  <p>Need to place a div container around 1, 2 &amp; 3 for one user and around 3, 4 &amp; 5 for another user and so on.  The parent container will always be around consecutive child divs.  </p>
  
  <p>EDIT:<br>
  Have tried to <a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/replaceChild" rel="nofollow"><code>replaceChild</code></a>  which works fine for 1 child but not multiples.  </p>