I'd like to be grab the next to last TR in a table.
$("#TableID tr:last")
gets the very last one, is there some way I can get the TR prior to that one?
When a negative index is specified for eq, it starts counting backwards from the end.
.eq( -index )
-index An integer indicating the position of the element, counting backwards from the last element in the set.
$('#TableID tr').eq(-2)
Sure, you could do it with the .slice method:
$('#TableID tr').slice(-2, -1).addClass('dark');
You can see it in action here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With