English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery last() Method

jQuery Traversal Methods

The last() method returns the last element of the selected elements.

To return the first element, usefirst()Method.

Syntax:

$("selector").last()

Example

Highlight the last paragraph:

$("document").ready(function(){
  $("p").last().css("background", "coral");
});
Test and See‹/›

Highlight the last paragraph within the last DIV element:

$("document").ready(function(){
  $("div p").last().css("background", "coral");
});
Test and See‹/›

Highlight the last unordered list:

$("document").ready(function(){
  $("ul").last().css("background", "coral");
});
Test and See‹/›

jQuery Traversal Methods