Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select next to last tr

Tags:

jquery

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?

like image 714
MushinNoShin Avatar asked Aug 24 '10 19:08

MushinNoShin


2 Answers

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)
like image 132
Anurag Avatar answered Nov 15 '22 12:11

Anurag


Sure, you could do it with the .slice method:

$('#TableID tr').slice(-2, -1).addClass('dark');

You can see it in action here.

like image 33
Pat Avatar answered Nov 15 '22 12:11

Pat