title: Wrap sibling elements in a DIV with javascript
body: <p>I want to turn the elements with class &quot;a&quot; into a div with javascript, without losing the order in which they are found with their siblings. Here is the code, I have not made much progress, I appreciate your help in advance.</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>const elementParent= document.querySelectorAll(".a");
  console.log(elementParent)
  
  const parent= elementParent[0].parentNode;
  console.log(parent)
  
  parent.innerHTML= elementParent[0]</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div style="display:flex"&gt;
    &lt;div class="cx"&gt;0&lt;/div&gt;
    &lt;div class="cx"&gt;0&lt;/div&gt;
    &lt;div class="a"&gt;A&lt;/div&gt;
    &lt;div class="a"&gt;A&lt;/div&gt;
    &lt;div class="b"&gt;b&lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  
  The final result of the html should be:</p>
  <pre><code>   &lt;div style=&quot;display:flex&quot;&gt;
        &lt;div class=&quot;cx&quot;&gt;0&lt;/div&gt;
        &lt;div class=&quot;cx&quot;&gt;0&lt;/div&gt;
        &lt;div&gt;
          &lt;div class=&quot;a&quot;&gt;A&lt;/div&gt;
          &lt;div class=&quot;a&quot;&gt;A&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;b&quot;&gt;b&lt;/div&gt;
      &lt;/div&gt;
  </code></pre>