Example 1 — Official Demo: $("ul li").last()
Take the last list item in document order (jQuery API example).
var $last = $("ul li").last();
console.log($last.length);
console.log($last.text().trim());
// Official: $( "ul li" ).last().addClass( "highlight" ); How It Works
- Match all items.
$("ul li")builds the full set. - Keep the end.
.last()drops every earlier item. - One-element set. Length is
1.

