开发者

jQuery Wrap a div from H2 until last paragraph

开发者 https://www.devze.com 2023-04-09 19:41 出处:网络
I want to wrap a <div> FROM THE BEGINNING of the <H2> up until the 开发者_开发技巧next <H2>, but it is only starting on the first paragraph.

I want to wrap a <div> FROM THE BEGINNING of the <H2> up until the 开发者_开发技巧next <H2>, but it is only starting on the first paragraph.

This is what I have, which ALMOST does the job:

$('h2:contains("test")').nextUntil('h2').wrapAll('<div class="wrapper" />');

Here's my 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>


I would try:

$("h2.test").nextUntil("h2").andSelf().wrapAll('<div class="wrapper" />');

It does seem to do the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号