我从dinamically的阵列(例如,4个各组中)包装的div的固定数目。 数.item
DIV从数组返回的IS未知......我需要在同一类递归添加到toghether包裹的div的那些群体:
<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>
这是tghe最终结果:
<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>
代码我使用包装的div:
var divs = $(".item");
for(var i = 0; i < divs.length; i+=4) {
divs.slice(i, i+4).wrapAll('<div class="wrapper"></div>');
}