jQuery 获取下一组类?
我有以下 HTML,例如
<body>
<div class="myCool">blah</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="myCool">blah</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
</body>
我想做的事情是从 myCool
开始,并将其和接下来的 4 个类 cool
包装到 div
中?所以看起来我有
<div id="1" class="myWrapped">
<div class="myCool">blah</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
</div>
<div id="2" class="myWrapped">
<div class="myCool">blah</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
</div>
什么想法可以做到这一点吗?
I have the following HTML like
<body>
<div class="myCool">blah</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="myCool">blah</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
</body>
What am I trying to do is start at myCool
and wrap it and the next 4 classes cool
into a div
? So it looks like
<div id="1" class="myWrapped">
<div class="myCool">blah</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
</div>
<div id="2" class="myWrapped">
<div class="myCool">blah</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
<div class="cool">some text</div>
</div>
Any ideas how I can do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
try
你可以这样做
you can do like this