jQuery在元素之间包装内容 [英] jquery wrap content between elements

查看:44
本文介绍了jQuery在元素之间包装内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些内容用<hr>标记分隔.我需要做的是将所有内容都包裹在开始标记和结束标记之间.

I have some content separated by <hr> markers. What I need to do is wrap everthing between the beginning maker and the ending marker.

给出此标记:

<hr class=begin>
 some content
 <some tags>
 more content
 <more tags>
<hr class=end>

这就是我需要的:

<hr class=begin>
 <div class=content>
   some content
   <some tags>
   more content
   <more tags>
 </div>
<hr class=end>

我可以使用.nextAll()来做到这一点,但似乎应该有一个更优雅的解决方案.

I can do this with .nextAll() but it seems like there should be a more elegant solution.

推荐答案

您可以使用 .nextUntil() 像这样:

You can use .nextUntil() like this:

$("hr.begin").nextUntil("hr.end").wrapAll("<div class='content'></div>");

这篇关于jQuery在元素之间包装内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆