Tiggles ツ of Speak Creative
11/28/2018 - 5:39 PM

Wrap a range of elements

select several children, and wrap x amount of them every so often.

<!--this is our html. we want to wrap 3 of the children < div > into another div-->



<div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
</div>

<!--This is what we want to result in: 
<div>
  <div class="new">
        <div></div>
        <div></div>
        <div></div>
   </div>
   <div class="new">
        <div></div>
        <div></div>
        <div></div>
   </div>
</div>-->
var divs = $("div > div");
for(var i = 0; i < divs.length; i+=3) {
  divs.slice(i, i+3).wrapAll("<div class='new'></div>");
}