jquery包装组的相邻元素 [英] jquery wrapping groups of adjacent elements
本文介绍了jquery包装组的相邻元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个cms,让用户在页面上插入内容块。用户可以使用不同类型的内容块,并且它们可以按任何顺序插入。示例性的高级dom结构可能如下所示:
I have a cms that lets users insert blocks of content on a page. There are different types of content block available to the user and they can be inserted in any order. An example high-level dom structure might look something like this:
<p>Some rich text</p>
<div class="box">...</div>
<div class="box">...</div>
<div class="box">...</div>
<h3>Some more rich text</h3>
<p>Lorem ipsum</p>
<div class="box">...</div>
<div class="box">...</div>
我想做的是将任何相邻的box因此,在上面的示例中,将插入两个containerdiv,因为有两组box div,导致:
What I want to do is wrap any adjacent 'box' divs in a wrapping 'container' div. So in the example above there would be two 'container' divs inserted as there are two groups of box divs, resulting in:
<p>Some rich text</p>
<div class="container">
<div class="box">...</div>
<div class="box">...</div>
<div class="box">...</div>
</div>
<h3>Some more rich text</h3>
<p>Lorem ipsum</p>
<div class="container">
<div class="box">...</div>
<div class="box">...</div>
</div>
我不认为有一个聪明的方法来做它与css选择器,