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
TrustyCoder
4,79911 gold badges73 silver badges126 bronze badges
-
Duplicate: stackoverflow.com/questions/3339172/… This question is in SO numerous times in different variations.spinon– spinon2010年07月28日 08:02:13 +00:00Commented Jul 28, 2010 at 8:02
4 Answers 4
$('tr').not('thead tr').addClass('selected')
answered Jul 28, 2010 at 8:02
Reigel Gallarde
65.5k21 gold badges126 silver badges142 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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
Andy E
346k86 gold badges482 silver badges452 bronze badges
Comments
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
Sinan ILYAS
1,4021 gold badge15 silver badges13 bronze badges
Comments
default