jQuery :last Selector

The jQuery :last selector selects the last element in a group. If you want to apply jQuery to the last element, you have to use this selector.

You don’t have to use any value to add to the selector. It required only the simple syntax to use as given below.


The above syntax can be used with the tag name to select the required tag. Let’s let it be more clear with the examples given below.

Examples of jQuery :last Selector

There are two examples listed below to explain the use of the jQuery :last Selector.

Let’s start with the example of using the table and selecting the last table row.

Use jQuery :last Selector to Select the Last Row of a Table

The below example selects the last row of the table and applies the color to it. There are three table rows and each row contains the text content.

Test it Live


Sr. No. Cricketer Name Wicket
1 Virat Kohli 189*
2 Ravindar Jadeja 134
3 Shikhar Dhawan 123*

The above example contains the button and the table. When you click the button, the selector selects the last row and apply the ‘orange’ color to the text content.

Select Last List Item

Let’s take an example of the list element and apply the CSS to the last list item. You have to use the jQuery :last selector as the example given below. It contains the five elements and applies the jQuery effect to the last element.


Test it Live


  • Select last list item.
  • Apply color to the last list item.
  • Learn jQuery from the website Tutorialdeep.
  • Create your own website with our web development guide.
  • Use live examples to learn everything.

The above example contains the list elements and the button. Click the button given above to apply the ‘orange’ color to the last list item. It happens because of the selector you are using to select only the end element in a group.