:nth-of-type(index) selects elements that are the nth sibling of their tag name under the same parent. Other tags between them do not change the count. Available since jQuery 1.9.
Remember
$(":nth-of-type(index | even | odd | equation)")
$("span:nth-of-type(1)") → first span (≡ :first-of-type)
$("span:nth-of-type(2)") → second span among spans
$("p:nth-of-type(even)") → even paragraph positions
$("span:nth-child(2)") → 2nd child among ALL tags
$("span:nth-last-of-type(2)") → 2nd span from the end
Pick a tag, then pass an index, keyword, or equation counted among that tag only — from the start.
Choose the element type (span, p, li, and so on).
Pass a 1-based index among same-type siblings, or even/odd/An+B.
Ignore other tag names when counting — they do not shift of-type indexes.
Use :nth-child() if every sibling type should count.
Piece
Required?
Role
Base / type
Usually
Tag name that defines the of-type group
:nth-of-type(…)
Yes
Forward index within that type
Argument
Yes
Index, even/odd, or equation
Pseudocode
Pseudocode
for each element E matching base:
sameType = siblings of E.parent with tagName === E.tagName
index = 1-based position of E in sameType (from start)
if index matches (n | even | odd | An+B):
keep E
return jQuery(kept)
Reference
Cheat Sheet
Keep these facts handy while counting same-type siblings from the start.
Topic
Detail
Syntax
$(":nth-of-type(n | even | odd | An+B)")
Counting
1-based among same tag, from the start
(1)
Same as :first-of-type
vs :nth-child()
Same type only vs all children
vs :nth-last-of-type()
From start vs from end
Since
jQuery 1.9 (CSS)
Try it
Live Preview
Pick a pattern against the official-style span groups (and a mixed block).
Three span groups mirror the official demo names; mixed shows of-type vs child.
JohnKimAdamRafaelOleg
DaveAnn
MauriceRichardRalphJason
note
FirstSpanSecondSpan
Result
$("span:nth-of-type(2)")
matched: 4
text: Kim, Ann, Richard, SecondSpan
/* same-tag siblings, counted from the start */
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: span:nth-of-type(2)
Find each span that is second among its sibling spans (jQuery API example).
One line:$("span:nth-of-type(n)") means “the nth span among span siblings.”
Frequently Asked Questions
:nth-of-type(index) selects elements that are the nth sibling of their tag name under the same parent. $("span:nth-of-type(2)") matches the second span among span siblings — regardless of other tag types nearby.
:nth-child() counts every sibling element. :nth-of-type() counts only siblings with the same tag. A leading p before spans means span:nth-child(1) fails, but span:nth-of-type(1) still matches the first span.
Yes. Both select the first element of that tag name among siblings under the same parent.
Yes. Per CSS and jQuery docs, counting starts at 1. This differs from .eq(), which uses 0-based indexing on a flat collection.
Official docs support :nth-of-type(even), odd, 3n, and 3n+1 — evaluated among same-type siblings only, so other tags between them do not shift indexes.
jQuery 1.9. It follows the W3C CSS specification and works via querySelectorAll in modern browsers.