Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get penultimate element

Is there a way in jQuery using selectors to identify the penultimate element?

Is there something like a :last-1?

The list can be any length so i cant use 'eq'

Any help would be much appreciated.

A.

like image 775
Adi Avatar asked Feb 25 '10 14:02

Adi


People also ask

How do I get the last element in a list?

To get the last element of the list using list. pop(), the list. pop() method is used to access the last element of the list.

How do I find the second last element in an array?

To get the second to last element in an array, call the at() method on the array, passing it -2 as a parameter, e.g. arr.at(-2) . The at method returns the array element at the specified index.

How do I get the last element in Python?

The best way to get the last element of a list in Python is using the list[-1]. Python allows you to use negative indices, which count from the end of the list instead of the beginning. So list[-1] gets the last element, list[-2] gets the second to last.

How do I get the last 3 elements of a list in Python?

Python3. The inbuilt functions can also be used to perform this particular task. The islice function can be used to get the sliced list and reversed function is used to get the elements from rear end.


1 Answers

Can't see your html but try this:

$("a:last").prev();

That should give you the one before the last element.

You could even try this:

$("a:last").eq(-1);
like image 162
Sarfraz Avatar answered Oct 06 '22 11:10

Sarfraz