【发布时间】:2013-09-11 21:37:17
【问题描述】:
我有一些类似于以下的标记:
<h3>A Heading</h3>
<p>Here is a paragraph.</p>
<ul>
<li>First</li>
<li>Second</li>
</ul>
<blockquote>Here's 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>
我想将每个h3 以及直到下一个h3 的所有内容都包含在一个div 中。
结果应该是:
<div>
<h3>A Heading</h3>
<p>Here is a paragraph.</p>
<ul>
<li>First</li>
<li>Second</li>
</ul>
<blockquote>Here's 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>
我发现了类似的问题,例如this one。它使用.nextUntil() 和.andSelf() 的组合(或.addBack() 一旦我的编辑被批准),但这会将h3s 和separate divs 之间的内容包装起来.
【问题讨论】:
标签: javascript jquery selector siblings wrapall