: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.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$(":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
Call
What it does
:only-of-type
Learn the jQuery :only-of-type selector: match elements with no same-tag siblings, official button:only-of-type demo, vs :only-child and :first-of-type/:last-of-type, examples, pitfalls, and FAQs.
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Choose the element type (button, p, and so on).
Step 2
Add :only-of-type — e.g. button:only-of-type.
Step 3
Confirm no sibling shares that same tag name.
Return Value
Return Value
Description
See examples
Check the examples below for what this API returns in common cases.
jQuery Examples
Example 1 — Official Demo: button:only-of-type
Find buttons that are the only button under their parent (jQuery API example).
Two buttons. Official rule: same element name → no only-of-type match.
First still works. One button is :first-of-type.
Last still works. The other is :last-of-type.
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.