tags:

views:

35

answers:

3

Hi, 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>
+3  A: 

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');
Andy E
+1  A: 

You can exclude thead using not

$('#mytable tr').not('thead tr')
Sarfraz
+1  A: 
$('tr').not('thead tr').addClass('selected')
Reigel