Latest web development tutorials

jQuery: nth-last-child () selector

jQuery selector jQuery selector

Examples

<P> Select the element belonging to the third child element of its parent element and a child element from the last start counting:

$("p:nth-last-child(3)")

try it"

Definition and Usage

: nth-last-child (n ) selector selects all elements that belong to its parent element is not limited to the type of n th element from the last child element count.

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


grammar

:nth-last-child( n |even|odd| formula )

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

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


Examples

Try - Example

Each <p> element to select all <div> element is the first child element, a child element from the last start counting
<P> element How to select all <div> element is the first child element, a child element from the last count.

Using equation (an + b)
How to use a formula (an + b) to select a different sub-elements, beginning from the last child element count.

Use "even" and "odd"
How to use the even and odd to select a different sub-elements, beginning from the last child element count.

: 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