:only-of-type selects every element that has no siblings with the same element name under its parent. Official docs: if the parent has other children with the same tag, nothing is matched. Other tags are allowed. Available since jQuery 1.9. Standard CSS.
Remember
$(":only-of-type")
$("button:only-of-type") → sole button (spans OK)
$("p:only-of-type") → sole p among siblings
<div><button></button></div> → matches
<div><button></button><span></span></div> → matches
<div><button></button><button></button></div> → no match
Pick a tag, then keep elements that are unique of that tag under their parent.
Choose the element type (button, p, and so on).
Add :only-of-type — e.g. button:only-of-type.
Confirm no sibling shares that same tag name.
Remember: siblings of other tags do not block the match.
Piece
Required?
Role
Type / context
Usually
Limits which tags are tested
:only-of-type
Yes
Requires zero same-tag siblings
Other-tag siblings
—
Allowed; do not block a match
Pseudocode
Pseudocode
candidates = find(baseSelector)
result = empty
for each el in candidates:
sameTag = siblings of el with tagName == el.tagName
if sameTag.length == 1 and sameTag[0] == el:
keep el
return jQuery(result)
Reference
Cheat Sheet
Keep these facts handy while matching unique tag siblings.
Topic
Detail
Syntax
$(":only-of-type") / $("sel:only-of-type")
Rule
No sibling with the same tag name
Other tags
Allowed next to the match
vs :only-child
Same-tag only vs any element sibling
vs first + last of type
Same as :first-of-type:last-of-type
CSS?
Yes — native querySelectorAll
Since
jQuery 1.9
Try it
Live Preview
Run selectors on the official-style demo: five boxes with buttons and optional spans.
Official pattern: lone buttons match even beside spans; two buttons in one box do not.
None
Sibling!Sibling!
Result
$("button:only-of-type")
matched: 3
hits: box 2 → Sibling!; box 4 → Sibling!; box 5 → Sibling!
/* same-tag siblings block; other tags do not */
Code
jQuery Examples
Short, copy-ready snippets. Open a browser console with jQuery loaded, or use Try It Yourself for a live editor.
Example 1 — Official Demo: button:only-of-type
Find buttons that are the only button under their parent (jQuery API example).
Keep unique paragraphs. One article has a single p.
Skip multi-paragraph articles. Two ps → neither matches.
Headings OK. An h2 sibling does not block p:only-of-type.
Edge Cases & Pitfalls
Check these before relying on :only-of-type in real projects.
same-tag
Duplicate tags block
Two buttons (or two ps) under one parent → zero only-of-type matches for that tag.
compare
Not the same as :only-child
Other tags are allowed here. Need absolute solitude? Use :only-child.
scope
Prefix with a type
Prefer button:only-of-type over bare :only-of-type to avoid surprising matches.
version
Since jQuery 1.9
Older than 1.9? This pseudo-class is unavailable — upgrade or use a manual same-tag sibling check.
Compatibility
Browser Support
:only-of-type is standard CSS, available in jQuery since 1.9. It works with native querySelectorAll in modern browsers.
✓ jQuery 1.9+ · CSS standard
jQuery :only-of-type
Works in all modern browsers with jQuery or native CSS. Same meaning in stylesheets and selectors.
100%modern browsers
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
:only-of-typeCSS + jQuery
Bottom line: Safe to use in jQuery and plain CSS — prefer a typed form like button:only-of-type for clarity.
Analysis
Performance Notes
Approach
Cost
Best for
$("button:only-of-type")
Native QSA path
Typical jQuery use
$("article p:only-of-type")
Smaller scoped set
Large documents
document.querySelectorAll(...)
Native CSS
No jQuery needed
Because :only-of-type is CSS, browsers can optimize it. Prefer a typed, scoped selector over bare $(":only-of-type") on huge pages.
Remember
Key Takeaways
Role: match elements with no same-tag siblings under the same parent.
Other tags OK: spans next to a lone button still match button:only-of-type.
vs only-child: use :only-child when any element sibling should block.
Equivalent: same idea as :first-of-type:last-of-type.
One line::only-of-type means “unique among siblings of this tag” — other tags may sit nearby.
Frequently Asked Questions
:only-of-type selects every element that has no siblings with the same element name under the same parent. $("button:only-of-type") matches the sole button in a div even when span siblings exist. Available since jQuery 1.9.
Nothing matches for that parent. Official docs: if the parent has other child elements with the same element name, :only-of-type matches nothing. Two buttons in one div means neither matches.
:only-child requires no element siblings at all. :only-of-type only compares same-tag siblings — a lone button beside spans matches button:only-of-type but not button:only-child.
Yes in practice. When exactly one element of a tag exists among siblings, it is both :first-of-type and :last-of-type — so p:first-of-type:last-of-type matches the same nodes as p:only-of-type.
Yes. :only-of-type is standard CSS and works with native querySelectorAll — e.g. document.querySelectorAll("p:only-of-type"). jQuery has supported it since 1.9.
Yes. Prefer $("button:only-of-type") or $("article p:only-of-type") over bare $(":only-of-type") so the intent and scope stay clear.