: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().
Remember
// 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");
Select with CSS first, then take the final match from that set.
Build a matched set with a pure CSS selector: $("tr") or $("ul.nav li").
Chain .last() to keep only the final element.
Use the result — .text(), .addClass(), events.
Avoid putting :last inside the selector string in new code.
Use :last-child when you need one match per parent.
Piece
Required?
Role
CSS selector
Yes
Builds the matched set
.last()
Preferred
Keeps only the final match
:last
Legacy
Same idea inside the selector (deprecated)
Pseudocode
Pseudocode
build a matched set with a CSS selector
e.g. all tr elements in document order
keep only the final item in that set
→ result length is 0 or 1
.compare with :last-child:
for each parent, keep the last child
→ result may contain many elements
Reference
Cheat Sheet
Keep these facts handy while picking the last matched element.
Topic
Detail
Prefer
$("elem").last()
Legacy
$("elem:last") (deprecated 3.4)
Since
jQuery 1.0
Matches
0 or 1 element
Equivalent
:eq(-1) / .eq(-1)
vs :last-child
One from set vs one per parent
CSS?
No — jQuery extension
Official demo
$("tr").last()
Try it
Live Preview
Mark the last row with .last(), compare with :last-child, or count matches.
Two lists below. .last() returns one li; :last-child can return two.
A1
A2
A3
B1
B2
Result
Ready — pick an action and click Run.
Code
jQuery Examples
Short, copy-ready snippets. Use Try It Yourself for a live editor.
Example 1 — Official $("tr").last()
Mark the last table row (official demo idea, CSS-free).
Same set. Both pick the final p in document order.
Method.$("p").last() is the recommended form.
Selector.$("p:last") still works but is deprecated since 3.4.
Habit. Write new code with .last() only.
Edge Cases & Pitfalls
Check these when the last match is not what you expected.
deprecated
Avoid :last in new selectors
Deprecated since jQuery 3.4. Prefer $("elem").last() after a CSS selector.
vs
Not the same as :last-child
.last() returns one element from the set. :last-child is about parent/child position and can match many.
scope
The set comes first
$("ul.nav li").last() and $("li").last() can differ — the CSS selector defines which elements compete for “last”.
perf
Not native CSS
:last cannot use querySelectorAll. Selecting with CSS first, then .last(), is faster on large pages.
Compatibility
Browser Support
:last is a jQuery extension (not standard CSS). Available since 1.0, deprecated in 3.4. Prefer .last(), which works in every browser that runs your loaded jQuery version.
✓ Deprecated · jQuery 1.0+
jQuery :last / .last()
The selector still works in jQuery 3.x but is deprecated. Use .last() for new code — same result, better practice.
1.0+jQuery since
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
:lastDeprecated 3.4
Bottom line: Safe to learn for reading old code. Write new code with $("elem").last() instead of $("elem:last").
Analysis
Performance Notes
Approach
Cost
Best for
$("ul.nav li").last()
Cheap
Scoped lists (preferred)
$("li").last()
Cheap–moderate
Page-wide last item
$("li:last")
Moderate
Legacy only — avoid in new code
Pure CSS selection can use the browser engine; :last cannot. Chain .last() after CSS for the best of both.
Remember
Key Takeaways
Role: keep only the last element in a matched set (0 or 1).
Prefer:$("elem").last() over deprecated $("elem:last").
vs :last-child: one from the set vs one per parent.
Scope: the CSS selector decides which elements compete for “last”.
One line: use .last() to pick the final element in a jQuery set — not :last-child, and not the deprecated :last selector.
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.