2012-10-19 29 views
0

嗨我有一張桌子裏面我有一張桌子。如何編寫jquery選擇器以僅獲取父錶行?jquery只選擇父表的行

<table class="required_capacity"> 
<tr> 
    <td>Row1</td> 
    <td>Row1</td> 
</tr> 
<tr> 
    <td colspan="2"> 
     <table> 
      <tr> 
       <td>Some Text ... </td> 
      </tr> 
      <tr> 
       <td>Some Text ... </td> 
      </tr> 
     </table> 
    </td> 
</tr> 
<tr> 
    <td>Row 3</td> 
    <td>Row 3</td> 
</tr> 

上面的html代碼

我需要得到的只有$( 'required_capacity')錶行。我試過這個選擇器得到行

$('.required_capacity_table').children('tr') 

但它在邊桌行也給?

+0

這個類名用在另一個表中,然後它也得到另一個表的tr,所以你可以使用表的id(在你的表中應用id)。 – Hkachhia

+0

謝謝Harry我用id試過也沒用,它返回內錶行 – Prasanna

回答

7

試試這個

$('.required_capacity_table > tbody > tr') 

DEMO

+0

我試過這樣也得到了同樣的結果。結果包括內錶行我需要只有外表行 – Prasanna

+0

我已經更新了答案 –

+0

謝謝Zoltan Toth它的工作原理 – Prasanna

0

使用本。

$('.required_capacity_table > tr')