:last-of-type (since jQuery 1.9) selects every element that is the last among siblings of the same tag name. Unlike :last-child, a different tag after it does not block the match.
Remember
// Official pattern — last span among siblings
$("span:last-of-type");
// Last paragraph in each article
$("article p:last-of-type");
// Same idea as :nth-last-of-type(1)
$("li:nth-last-of-type(1)");
// Stricter: must also be the final child
$("span:last-child");
Remember: only siblings with the same tag are compared.
Use :last-child when the element must also be the final child.
Piece
Required?
Role
Tag / filter
Recommended
e.g. span, p, td
:last-of-type
Yes
Last sibling of that tag name
Parent scope
Optional
Limits which trees are searched
Pseudocode
Pseudocode
for each element matching the left side (e.g. span):
look at its parent
find all siblings with the same tag name
if this element is the last of those siblings:
include it in the result
result may contain many elements
→ one match is possible for each parent + tag
.compare with :last-child:
the element must also be the final child
of any tag type under that parent
Reference
Cheat Sheet
Keep these facts handy while selecting last-of-type elements.
Topic
Detail
Selector
$("elem:last-of-type")
Since
jQuery 1.9
Matches
0–many (one per parent + tag)
Equivalent
:nth-last-of-type(1)
vs :last-child
Same tag only vs final child of any tag
vs .last()
Per parent + type vs one from the set
CSS?
Yes — standard CSS pseudo-class
Official demo
$("span:last-of-type")
Try it
Live Preview
Mark last-of-type spans, compare with :last-child, or count matches.
Sample blocks below. A trailing p blocks :last-child on spans, not :last-of-type.
CoreyYehudaTodd
note
JörnScottTimo
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 span:last-of-type
Mark the last span in each div (official demo idea, CSS-free).
Last td.td:last-of-type is the last td among siblings.
Mark. An asterisk is appended for a clear visual cue.
Note. In a row of only td cells, this matches td:last-child too.
Edge Cases & Pitfalls
Check these when a last-of-type selector surprises you.
siblings
Compares same tag only
A following p does not stop span:last-of-type. Use :last-child if the element must be the final child.
vs
Not the same as .last()
.last() returns one element from the set. :last-of-type is about tag position among siblings.
scope
Bare :last-of-type is broad
Prefer $("p:last-of-type") or a parent scope so you do not restyle every last-of-type node on the page.
version
Needs jQuery 1.9+
Older jQuery builds before 1.9 do not support :last-of-type. Upgrade or use a different filter.
Compatibility
Browser Support
:last-of-type is a standard CSS pseudo-class. jQuery has supported it since 1.9. It also works with native querySelectorAll in modern browsers.
✓ Stable · jQuery 1.9+
jQuery :last-of-type
Works in every browser that runs jQuery 1.9+. Behavior matches the CSS :last-of-type 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-of-typeUniversal
Bottom line: Safe for everyday UI. Prefer typed selectors (span:last-of-type) and remember it can match once per parent for that tag.
Analysis
Performance Notes
Approach
Cost
Best for
Scoped $("article p:last-of-type")
Cheap
Articles, cards, local blocks
Typed $("span:last-of-type")
Cheap–moderate
Page-wide last-of-type tags
Bare $(":last-of-type")
Moderate
Avoid — too broad
Type filters are fast when scoped. Start from a known parent when the page is large.
Remember
Key Takeaways
Role: match the last sibling of each tag name under a parent.
Many matches: one last-of-type is possible for each parent + tag.
vs :last-child: same tag only vs must be the final child.
Scope: prefer $("p:last-of-type") over bare $(":last-of-type").
One line::last-of-type picks the last sibling of a given tag — even if another tag type follows.
Frequently Asked Questions
:last-of-type selects every element that is the last among siblings with the same element name (tag). $("span:last-of-type") matches the last span in each parent. Available since jQuery 1.9.
:last-child requires the element to be the last child among all element types. :last-of-type only compares siblings with the same tag. If a <p> comes after a <span>, the span is not :last-child but can still be span:last-of-type.
Yes. In CSS, :last-of-type is equivalent to :nth-last-of-type(1). Both select the last element of that tag name among siblings under the same parent.
.last() returns only one element — the last in the entire jQuery matched set. :last-of-type can return many — one per parent for that tag type.
Another element type may be the last child. Example: <div><span>A</span><span>B</span><p>Footer</p></div> — the last span matches span:last-of-type but not span:last-child because the paragraph is the last child.
Yes — $("p:last-of-type") or $("article p:last-of-type") is clearer than bare $(":last-of-type"). Scoping to a parent class or ID avoids matching unintended nodes across the page.