jQuery last() method

As its name implies, the last() method returns the last element of the selected elements. It is an inbuilt method in jQuery. If we need to get the first element, we can use the first() method.

Syntax

This method doesn't accept any argument. The selector in the above syntax is mandatory to be specified.

Let's see some of the illustrations to understand how to use the last() method.

Example1

In this example, we are using the last() method to get the last span element from the set of elements.

Test it Now

Output

After the execution of the above code, the output will be -

jQuery last() method

After clicking the given button, the output will be -

jQuery last() method

Example2

In this example, we are using the last() method to get the last paragraph element from the set of elements. We are using the p as the selector, so the method will return the last paragraph element.

Test it Now

Output

After the execution of the above code, the output will be -

jQuery last() method

After clicking the given button, the output will be -

jQuery last() method




Contact US

Email:[email protected]

jQuery last() method
10/30