TrustyCoder
TrustyCoder

Reputation: 4789

select rows in a table except the table header rows

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>

Upvotes: 22

Views: 23248

Answers (4)

Sinan ILYAS
Sinan ILYAS

Reputation: 1373

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

$('#mytable tr:not(:first)')

Upvotes: 5

Reigel Gallarde
Reigel Gallarde

Reputation: 65264

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

Upvotes: 25

Sarfraz
Sarfraz

Reputation: 382696

You can exclude thead using not

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

Upvotes: 4

Andy E
Andy E

Reputation: 344567

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');

Upvotes: 24

Related Questions