jQuery: nth-child () selector
Examples
Each <p> element of its parent element belonging to selected third sub-element:
try it"
Definition and Usage
: nth-child (n) selector selects all elements that belong to its parent element is not limited to the type of n th element.
Tip: Use : nth-of-type () selector to select all elements that belong to its parent element is not limited to the type of n th element.
grammar
参数 | 描述 |
---|---|
n | 要匹配的每个子元素的索引。 必须是一个数字。第一个元素的索引号是 1。 |
even | 选取每个偶数子元素。 |
odd | 选取每个奇数子元素。 |
formula | 规定哪个子元素需通过公式 ( an + b ) 来选取。
实例:p:nth-child(3n+2) 选取每个第三段,从第二个子元素开始。 |
Try - Example
Each <p> element to select all <div> elements in the second sub-element
Each <p> element How to select all <div> elements in the second sub-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.