:last-child (since jQuery 1.1.4) selects every element that is the last child of its parent. Unlike .last(), which returns one element from a set, :last-child can match one per parent.
Remember
// Official pattern — last span in each div
$("div span:last-child");
// Last list item in each ul
$("ul li:last-child");
// Same idea as :nth-last-child(1)
$("p:nth-last-child(1)");
// Not the same as .last() (one element only)
$("li").last();
Remember: the element must be the final element child of its parent.
Use .last() only when you want one match from the whole set.
Piece
Required?
Role
Tag / filter
Recommended
e.g. li, span, td
:last-child
Yes
Must be the last element sibling
Parent scope
Optional
Limits which trees are searched
Pseudocode
Pseudocode
for each element matching the left side (e.g. span):
look at its parent
if this element is the last element child of that parent:
include it in the result
result may contain many elements
→ one match is possible for each parent
.compare with .last():
take the full matched set
keep only the final item in that set
→ always 0 or 1 element
Reference
Cheat Sheet
Keep these facts handy while selecting last children.
Topic
Detail
Selector
$("elem:last-child")
Since
jQuery 1.1.4
Matches
0–many (one per parent possible)
Equivalent
:nth-last-child(1)
vs .last()
Per parent vs one from the set
vs :last-of-type
Last of any tag vs last of same tag
CSS?
Yes — standard CSS pseudo-class
Official demo
$("div span:last-child")
Try it
Live Preview
Mark the last child in each list, compare with .last(), or count matches.
Sample lists below. :last-child can match once per parent.
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 div span:last-child
Mark the last span in each div (official demo idea, CSS-free).
Last cell.td:last-child is the final cell in that row.
Mark. An asterisk is appended for a clear visual cue.
Note. Header cells use th — this selector targets td only.
Edge Cases & Pitfalls
Check these when a last-child selector returns nothing.
siblings
Must be the final element child
If another element follows your target, :last-child will not match — try :last-of-type instead.
vs
Not the same as .last()
.last() returns one element from the set. :last-child is about parent/child position.
scope
Bare :last-child is broad
Prefer $("li:last-child") or a parent scope so you do not restyle every last child on the page.
text
Text nodes do not count
Whitespace text between tags is ignored for child-index — only element nodes matter.
Compatibility
Browser Support
:last-child is a standard CSS pseudo-class. jQuery has supported it since 1.1.4. It also works with native querySelectorAll in modern browsers.
✓ Stable · jQuery 1.1.4+
jQuery :last-child
Works in every browser that runs your loaded jQuery version. Behavior matches the CSS :last-child rule.
100%CSS selector
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
:last-childUniversal
Bottom line: Safe for everyday UI. Prefer typed selectors (li:last-child) and remember it can match once per parent.
Analysis
Performance Notes
Approach
Cost
Best for
Scoped $("ul.nav li:last-child")
Cheap
Menus, cards, local lists
Typed $("li:last-child")
Cheap–moderate
Page-wide last items
Bare $(":last-child")
Moderate
Avoid — too broad
Child filters are fast when scoped. Start from a known parent when the page is large.
Remember
Key Takeaways
Role: match elements that are the last child of their parent.
Many matches: one last-child is possible for each parent.
vs .last(): position in the DOM vs position in a jQuery set.
Scope: prefer $("li:last-child") over bare $(":last-child").
One line::last-child picks the final element child of each parent — not just the last item in a jQuery set.
Frequently Asked Questions
:last-child selects every element that is the last child of its parent. $("div span:last-child") matches the last span inside each div — so multiple elements can match. Available since jQuery 1.1.4.
.last() returns only one element — the last in the entire jQuery matched set. :last-child can return many — one per parent. The official jQuery docs highlight this distinction.
Yes. In CSS, :last-child is equivalent to :nth-last-child(1). Both select elements that are the last child of their parent.
:last-child requires the element to be the final child among all siblings. :last-of-type selects the last sibling of that tag name, even if other tag types follow it.
If another element sibling comes after your target, it will not match. Only the final element child of the parent matches, regardless of tag name. Text nodes do not count as element children.
Yes — $("li:last-child") or $("div span:last-child") is clearer than bare $(":last-child"). Scoping to a parent class or ID avoids matching unintended last children across the page.