:last (since jQuery 1.0) selects exactly one element — the last in the matched set, in document order. It is a jQuery extension (not CSS) and is deprecated since 3.4. Prefer .last().
Syntax
Start with these common calls. Keep them short and readable.
jQuery
// Preferred (official pattern)
$("tr").last();
// Legacy selector (deprecated 3.4)
$("tr:last");
// Same idea as :eq(-1)
$("tr:eq(-1)");
// Not the same as :last-child (many per parent)
$("tr:last-child");
Call
What it does
CSS selector
Builds the matched set
.last()
Keeps only the final match
:last
Same idea inside the selector (deprecated)
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Build a matched set with a pure CSS selector: $("tr") or $("ul.nav li").
Step 2
Chain .last() to keep only the final element.
Step 3
Use the result — .text(), .addClass(), events.
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
jQuery Examples
Example 1 — Official $("tr").last()
Mark the last table row (official demo idea, CSS-free).
Equivalence.:last equals :eq(-1) in the matched set.
Modern. Prefer .last() or .eq(-1) over the selector form.
Result. Both texts match for the same list.
Frequently Asked Questions
:last selects exactly one element — the last in the matched set that precedes it, in document order. $("tr:last") matches only the last table row among all tr elements in scope. Available since jQuery 1.0.
Yes. Official jQuery documentation states that :last is equivalent to :eq(-1). Both return a single element at the final index of the matched set.
Yes — deprecated in jQuery 3.4. Official docs recommend removing :last from selectors and using the .last() method after a pure CSS selector instead: $("tr").last() rather than $("tr:last").
:last returns one element total from the matched set. :last-child can return many — one per parent. Official docs highlight this distinction explicitly.
No. :last is a jQuery extension and not part of the CSS specification. It does not work in native querySelectorAll. Use .last() on a CSS-selected collection for modern code.
Prefer .last(). Select with a CSS selector first, then chain .last(). That matches the official recommendation after the 3.4 deprecation and can use native querySelectorAll for the first step.