如何使用jQuery对一定数量的元素进行分组? [英] How do i group a certain number of elements with jQuery?
问题描述
我需要一些有关使用jQuery选择项目的快速帮助.这可能是一个非常简单的解决方案,但是...除了克隆和复制元素外,我看不到任何正确的解决方案. 所以,我们开始.我在页面上有这种结构:
I need some quick help on selecting items with jQuery. It might be a very simple solution, but... I can't see one right one besides cloning and duplicating elements. So, here we go. I have this kind of structure on a page:
我想将每个六个元素分组为一个包装器元素,以便具有.quotesWrapper > (.sixQuoteWrapper > .quote * 6) * 4
.
I want to group each six elements into a wrapper element, in order to have .quotesWrapper > (.sixQuoteWrapper > .quote * 6) * 4
.
有什么主意我能做到这一点吗?谢谢!
Any idea how i could achieve this? Thanks!
推荐答案
如果我再给我几分钟的时间,我相信我可以在没有它们的情况下得到它,但这确实可行.
I'm sure i could get this without an each if i gave it a few more mins, but this works.
这是 js小提琴
$('.quotesWrapper .quote.split').each(function(){
$(this).nextUntil('.quote.split')
.andSelf()
.wrapAll('<div class="wrap" />')
});
这篇关于如何使用jQuery对一定数量的元素进行分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!