Reputation: 1690
I want to know how to get the last visible child of an HTML table using jQuery? The reason I ask is, I cannot use CSS 3 to get the last child because older browsers do not support it and this is kind of a legacy projects I am working on.
I have a table structure like this:
<table id="table">
<tr>
<td>Some name</td>
</tr>
<tr>
<td>Some name</td>
</tr>
<tr style="display:none;">
<td>Some name</td>
</tr>
</table>
The last table row is not visible and it gets shown when clicking on a plus sign next to the data but it is not relevant. I want to find out how to get the last visible table row using jQuery selectors.
Currently I am using
$last = $('#table').find('tbody tr:last-child');
$last.addClass('last-child');
But its actually returning the hidden table row.
Thank you in advance
Upvotes: 2
Views: 9282
Reputation: 13134
$last = $('#table').find('tbody tr:visible:last');
$last.addClass('last-child');
As Mathieu linked to.
Upvotes: 2
Reputation: 12142
try one of these
$last = $('#table').find('tbody tr:visible:last-child');
or
$last = $('#table').find('tbody tr:visible').is(':last-child');
Upvotes: 0