【发布时间】:2014-07-13 10:31:34
【问题描述】:
<h2 id="match" class="contentHeadline">Match only in here</h2>
<p>I don't if or how many dl+table live here.</p>
<dl><dt>Text</dt></dl>
<table class="groupTable"><td>1</td><td>Abc</td></table>
<dl><dt>Text</dt></dl>
<table class="groupTable"><td>2</td><td>Def</td></table>
<dl><dt>Text</dt></dl>
<table class="groupTable"><td>3</td><td>Ghi</td></table>
<p class="foo">Maybe some text lives here. I should not float.</p>
我想将每对 dl + table 包装在一个 div.box(浮动)中,但只能直接在 h2#match 下,直到后面有其他内容(.foo 或标题)。
$("dl").each(function(){
$(this).next('.groupTable').andSelf()
.wrapAll('<div class="box"></div>');
});
/* Clear */
$('<div class="clear"></div>').after('.box:last');
nextUntil() 单独包装 dl 和表格。
atm 测试组被错误包装。
【问题讨论】:
-
“测试”组的表格元素没有
class = 'groupTable' -
嗯,看起来你已经在 desired result 小提琴中工作了.. 那么问题是什么..?顺便说一句,“但仅在 h2#match 的正下方,直到后面的其他内容(.foo 或标题)”是什么意思。 ..??
-
期望的结果是明确它应该如何看待最后。我用 jquery 将它们包装到 div.box 中。我的意思是我需要在 h2#match 下选择每个 dl+table.groupTable 直到其他非 dl+table 的东西像 p.foo 或一些 h2 一样跟随。