I'm dinamically wrapping a fixed number of divs from an array (e.g. 4 in each group).
The number of .item
div's returned from the array is unknown...
I need to recursively add the same class to those groups of divs wrapped toghether:
<div class="wrapper">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<div class="wrapper">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<!-- more divs follow... -->
<div class="wrapper">
...
</div>
<div class="wrapper">
...
</div>
and this is tghe final result:
<div class="wrapper">
<div class="item div-01"></div>
<div class="item div-02"></div>
<div class="item div-03"></div>
<div class="item div-04"></div>
</div>
<div class="wrapper">
<div class="item div-01"></div>
<div class="item div-02"></div>
<div class="item div-03"></div>
<div class="item div-04"></div>
</div>
<!-- more divs follow... -->
<div class="wrapper">
...
</div>
<div class="wrapper">
...
</div>
the code I'm using to wrap the divs:
var divs = $(".item");
for(var i = 0; i < divs.length; i+=4) {
divs.slice(i, i+4).wrapAll('<div class="wrapper"></div>');
}