VOOZH about

URL: https://www.geeksforgeeks.org/jquery/jquery-last-method/

⇱ jQuery last() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

jQuery last() Method

Last Updated : 7 Jul, 2023

The last() function is an inbuilt function in jQuery which is used to find the last element of the specified elements.

Syntax:

$(selector).last()

Here selector is the selected elements.

Parameters: It does not accept any parameter.

Return value: It returns the last element out of the selected elements.

JavaScript code to show the working of this function:

Example 1:

In this code the background-color of the last "p"element get changed.

Output:

👁 Image

Example 2:

In the above example the last elements with class "main" get highlighted.

Output:

👁 Image
Comment
Article Tags:

Explore