jQuery :nth-of-type() Selector
Example
Select the third
element of every
element:
$("p:nth-of-type(3)")
Try it »
Definition and Usage
:nth-of-type(n) selector selects all elements that are the n child of their parent, regardless of type.
Tip:Please use the :nth-child() selector to select theregardless of typechild of n child of their parent, regardless of type.
Syntax
:nth-of-type(
n
|even|odd|
formula
)
| Parameters | Description |
|---|---|
| n | The index of each child element to be matched. |
必须是一个数字。第一个元素的索引号是 1。 |
| even | Selects every even child element. | | odd | Selects every odd child element. | | formula | Specifies which child elements to select via the (an + b).
Example: p:nth-of-type(3n+2) selects every third element, starting from the second element. |
Try it - Example
element of every
Element
How to select all
element of every
.
Using the formula (an + b)
How to use the formula (an + b) to select different child elements.
Using "even" and "odd"
How to use even and odd to select different child elements.
Difference between :nth-child(), :nth-last-child(), :nth-of-type(), and :nth-last-of-type()
Difference between p:nth-child(2), p:nth-last-child(2), p:nth-of-type(2), and p:nth-last-of-type(2).
jQuery selector