我想包装一个<div>
从<H2>
开始直到下一个<H2>
,但只是从第一段开始。
这就是我所拥有的,它几乎可以完成工作:
$('h2:contains("test")').nextUntil('h2').wrapAll('<div class="wrapper" />');
这是我的 HTML:
/* from here */
<h2 class='test'>Include this in the wrap</h2>
<p>this</p>
<p>and this</p>
<p>and this</p> /* to here */
<h2 class='next'>before this</h2>
最佳答案
我会尝试:
$("h2.test").nextUntil("h2").andSelf().wrapAll('<div class="wrapper" />');
关于jquery-selectors - jQuery 将 H2 中的 div 包裹到最后一段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7628339/