Using jQuery, what selector do I use to get the last thead tr for each matching table?
On a single page, I have two tables. Each of them has a class of "data". Each of them has theads.
I want to apply formatting to the last row in each of the table's theads.
I originally had this:
$('table.data thead tr:last').children().addClass('col');
Which works fine if there is only one table on the page. But if there are multiple tables, that tr:last selector picks up the last开发者_运维知识库 tr for ALL of the tables matching the class, not EACH table.
How do I constrain this to operate on the last tr for each thead?
Thanks!
Use the :last-child
selector instead to get the one in each <thead>
, like this:
$('table.data thead tr:last-child').children().addClass('col');
//or possibly:
$('table.data thead tr:last-child > td').addClass('col');
精彩评论