jQuery last() Method

The jQuery last() method can be used to return the last item of the selected element. jQuery select last element from the selected group element whether it is table, list, or form.

jQuery last() Method

jQuery last() Method

jQuery select the last element with the last() method as given here below.

Syntax

The syntax of this method is given below:-

Syntax
$(selector).last()

Description of the Parameters

The description of these parameters is given below.

Parameter Name Description
selector Specify the group element to select its last item. You can use the element tag name, class name, or id to select. It is a required field.

jQuery last() Method to Select Last Element

If you want to select the last element of the selected group element, you have to use the method as given below. It doesn’t require any parameters to specify and use the method. After selecting the last element, you can apply CSS using the css() of jQuery.

Test it Live

Output

  • First Item
  • Second Item
  • Third Item
  • Last Item


You have to click the button given above to selects the last item of the list element. The above example applies the red color to the selected last list item.

Related jQuery Methods

I hope you like this tutorial on jQuery last() method.

References