22

How to select rows in a html table except the table header rows using jquery?

 <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>
Andy E
346k86 gold badges482 silver badges452 bronze badges
asked Jul 28, 2010 at 7:59
1

4 Answers 4

25
$('tr').not('thead tr').addClass('selected')
answered Jul 28, 2010 at 8:02
Sign up to request clarification or add additional context in comments.

Comments

24

You should wrap the rows in a <tbody> element (some browsers will do this anyway!), then select the children of that tbody:

$('#mytable > tbody > tr');
answered Jul 28, 2010 at 8:01

Comments

5

This selector selects all tr elements in #mytable except the first one (the header).

$('#mytable tr:not(:first)')
answered Jun 29, 2018 at 13:08

Comments

4

You can exclude thead using not

$('#mytable tr').not('thead tr')
answered Jul 28, 2010 at 8:01

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.