I have a markup similar to the following:
<h3>A Heading</h3> <p>Here is a paragraph.</p> <ul> <li>First</li> <li>Second</li> </ul> <blockquote>Here some other block-level element</blockquote> <h3>The Wrapping Should Stop Before This Heading, but a Second One Should Begin</h3> <ol> <li>First</li> <li>Second</li> </ol> <p>Notice the varying block-level elements? It probably doesn't make any difference.</p>
I want to wrap every h3
and everything except the next h3
in one div
.
The result should be:
<div> <h3>A Heading</h3> <p>Here is a paragraph.</p> <ul> <li>First</li> <li>Second</li> </ul> <blockquote>Here some other block-level element</blockquote> </div> <div> <h3>The Wrapping Should Stop Before This Heading, but a Second One Should Begin</h3> <ol> <li>First</li> <li>Second</li> </ol> <p>Notice the varying block-level elements? It probably doesn't make any difference.</p> </div>
I found similar questions, like this one . It uses a combination of .nextUntil()
and .andSelf()
(or .addBack()
after my editing has been approved), but this will wrap h3
and content between separate div
.
source share