select rows in a table except the table header rows

霸气de小男生 提交于 2021-02-18 04:09:33

问题


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>

回答1:


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



回答2:


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



回答3:


You can exclude thead using not

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



回答4:


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

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


来源:https://stackoverflow.com/questions/3350924/select-rows-in-a-table-except-the-table-header-rows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!