2010-07-28 21 views
15

Come selezionare le righe in una tabella html tranne le righe dell'intestazione della tabella utilizzando jquery?selezionare le righe in una tabella tranne le righe dell'intestazione della tabella

<table id="mytable"> 
     <thead> 
      <tr> 
       <th> 
        Foo 
       </th> 
       <td> 
        Lorem 
       </td> 
       <td> 
        Ipsum 
       </td> 
      </tr> 
     </thead> 
     <tr> 
      <th> 
       Bar 
      </th> 
      <td> 
       Dolor 
      </td> 
      <td> 
       Sit 
      </td> 
     </tr> 
     <tr> 
      <th> 
       Baz 
      </th> 
      <td> 
       Amet 
      </td> 
      <td> 
       Consectetuer 
      </td> 
     </tr> 
    </table> 
+0

Dupli cate: http://stackoverflow.com/questions/3339172/jquery-selector-to-filter-out-th-elements Questa domanda è in così tante volte in diverse varianti. – spinon

risposta

20
$('tr').not('thead tr').addClass('selected') 
21

Si dovrebbe avvolgere le righe in un elemento <tbody> (alcuni browser farà questo comunque!), Quindi selezionare i figli di quel tbody:

$('#mytable > tbody > tr'); 
4

È possibile escludere thead usando not

$('#mytable tr').not('thead tr') 
Problemi correlati