:first-of-type (since jQuery 1.9) selects every element that is the first among siblings of the same tag name. Unlike :first-child, an earlier sibling of a different tag does not block the match. It is equivalent to :nth-of-type(1).
Remember
// Official pattern — first span under each parent
$("span:first-of-type");
// First paragraph in each article
$("article p:first-of-type");
// Same as :nth-of-type(1)
$("span:nth-of-type(1)");
// Different from :first-child (any tag must be #1)
$("span:first-child");
Remember: only same-tag siblings matter for this filter.
Use :first-child when the element must be child #1 of any type.
Piece
Required?
Role
Tag name
Recommended
e.g. span, p, h2
:first-of-type
Yes
First sibling with that tag
Parent scope
Optional
Limits which trees are searched
Pseudocode
Pseudocode
for each element matching the left side (e.g. span):
look at its parent and same-tag siblings
if no earlier sibling has the same tag name:
include it in the result
result may contain many elements
→ one match is possible for each parent × tag
.compare with :first-child:
first-child → must be the first element child (any tag)
first-of-type → must be the first of this tag only
Reference
Cheat Sheet
Keep these facts handy while selecting first-of-type elements.
Topic
Detail
Selector
$("elem:first-of-type")
Since
jQuery 1.9
Matches
0–many (one per parent × tag possible)
Equivalent
:nth-of-type(1)
vs :first-child
Same-tag first vs absolute first child
CSS?
Yes — standard CSS pseudo-class
Official demo
$("span:first-of-type")
Try it
Live Preview
Mark first-of-type spans, compare with :first-child, or count matches.
Sample: two groups. Group B starts with em, so span:first-child fails there while span:first-of-type still matches.
Corey,Yehuda,Adam
Note:Nobody,Jörn,Scott
Result
Ready — pick an action and click Run.
Code
jQuery Examples
Short, copy-ready snippets. Prefer a typed selector over bare $(":first-of-type").
Example 1 — Official span:first-of-type
Mark the first span in each div — the documented pattern.
[lead] Intro paragraph…
(h2 before it does not block the match)
How It Works
Markup. An h2 is the first child.
Select.p:first-of-type finds the first paragraph.
Mark. Prepend a lead label.
Note.p:first-child would fail here.
Edge Cases & Pitfalls
These mix-ups cause most :first-of-type surprises.
vs child
Not the same as :first-child
Use :first-of-type for “first span/p/h2”. Use :first-child for “must be child #1”.
tag
Tag name matters
span and p each have their own first-of-type under the same parent.
scope
Bare $(":first-of-type") is broad
Prefix with a tag and parent scope to avoid matching the whole document.
version
Needs jQuery 1.9+
Older 1.x builds before 1.9 do not include this selector.
Compatibility
Browser Support
:first-of-type is a standard CSS pseudo-class. jQuery has supported it since 1.9. Works wherever your loaded jQuery build (and the browser CSS engine) runs.
✓ Stable · jQuery 1.9+
jQuery :first-of-type
Universal CSS / jQuery support on modern stacks. Prefer current jQuery 3.x+ for consistent selector engines.
100%CSS + jQuery
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
:first-of-typeUniversal
Bottom line: Safe for everyday UI. Prefer typed, scoped selectors over bare :first-of-type.
Analysis
Performance Notes
Approach
Cost
Best for
Scoped $("#main p:first-of-type")
Cheap
Typical UI highlighting
Bare $(":first-of-type")
Broader
Avoid on large pages
:first-child when you mean absolute first
Cheap
Stricter position checks
Modern browsers implement :first-of-type in native CSS. Keep selectors scoped so jQuery does less work.
Remember
Key Takeaways
Role: first sibling of a given tag name under each parent.
vs child: ignores earlier siblings of other tags.
Equals::nth-of-type(1).
Scope: prefer typed selectors like $("p:first-of-type").
One line::first-of-type finds the first sibling of a tag — use :first-child when position #1 among all tags is required.
Frequently Asked Questions
:first-of-type selects every element that is the first among siblings with the same tag name. $("span:first-of-type") matches the first span under each parent. Available since jQuery 1.9.
:first-child requires the element to be the first child of any tag. :first-of-type only compares same-tag siblings. If a <p> comes before a <span>, the span is not :first-child but can still be span:first-of-type.
Yes. In CSS, :first-of-type is equivalent to :nth-of-type(1).
Yes. It is a standard CSS pseudo-class and works with native querySelectorAll. jQuery has supported it since 1.9.
Another element type may be the first child. Example: <div><p>Intro</p><span>Lead</span></div> — the span matches span:first-of-type but not span:first-child.
Yes — $("p:first-of-type") or $("article h2:first-of-type") is clearer than bare $(":first-of-type"). Scope to a parent when possible.