Latest web development tutorials

jQuery: nth-of-type () selector

jQuery selector jQuery selector

Examples

Each <p> element of its parent element belonging to selected third <p> element:

$("p:nth-of-type(3)")

try it"

Definition and Usage

: nth-of-type (n ) selector selects all elements belonging to a particular type of parent element n th element.

Tip: Use : nth-child () selector to select all elements that belong to its parent element is not limited to the type of n th element.


grammar

:nth-of-type( n |even|odd| formula )

参数 描述
n 要匹配的每个子元素的索引。

必须是一个数字。第一个元素的索引号是 1。
even 选取每个偶数子元素。
odd 选取每个奇数子元素。
formula 规定哪个子元素需通过公式 ( an + b ) 来选取。
实例:p:nth-of-type(3n+2) 选取每个第三段,从第二段开始。


Examples

Try - Example

Each <p> element to select all <div> element of the second <p> element
Each <p> element How to select all <div> element of the second <p> element.

Using equation (an + b)
How to use a formula (an + b) to select a different sub-elements.

Use "even" and "odd"
How to select different even and odd sub-elements.

: nth-child () ,: nth -last-child () ,: nth-of-type () and: nth-of-last-type different between ()
p: nth-child (2), p: nth-last-child (2), p: nth-of-type (2) and p: between nth-of-last-type (2) are different.


jQuery selector jQuery selector