2013-01-23 40 views
0

我有一個看起來像這樣與「sibiling」和「不」選擇有問題

<h4></h4> 
<table></table> < want this 
...    < want all these tables 
<table></table> < want this 
<h4></h4> 
<table></table> < not this 
...    < not these 
<table></table> < not this 

我想選擇使用此jQuery選擇

$("h4:eq(0) ~ table.someClass:not(h4:eq(1) ~ table.somaClass)") 
第一 <h4>元素只表頁面

它不起作用 - 返回所有表。

回答

2

使用div有一個更簡單的測試 - 案件:

$('h4:first').nextUntil('h4').filter('div').css('background', 'green'); 

http://jsbin.com/ipuvix/3/

+0

謝謝!那nextUntil做這份工作! –

0

的選擇只會是:

$('h4:first ~ table').not('h4:nth_child(2) ~ table') 
+0

那隻返回表,我需要所有的人都在第一H4和沒有下第二H4元素表 –

+0

哦,好吧,我最初誤讀。我編輯了我的答案來糾正這個問題。 –

+0

這就是我正在嘗試,但無法得到正確的結果... –

0

jQuery的siblings selector選擇所有的兄弟姐妹

$('h4:first').siblings('table'); 
+0

返回所有表,因爲它們都在第一個h4元素下...我需要第一個h4下的表,直到第二個,第二個h4元素下的所有表需要被丟棄 –

+0

doh,對不起。答案是.nextUntil –

0

您可以使用jQuery Next()

$("h4").next("table")