jQuery :nth-last-child() 선택기

❮ jQuery 선택기

예시

마지막 자식부터 계산하여 부모의 세 번째 자식인 각 <p> 요소를 선택합니다.

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

정의 및 사용

:nth-last-child( n ) 선택자는 유형에 관계없이 마지막 자식부터 계산하여 부모의 n 번째 자식인 모든 요소를 ​​선택합니다.

팁: :nth-last-of-type() 선택기를 사용 하여 마지막 자식부터 계산하여 부모의 특정 유형 , n 번째 자식인 모든 요소를 ​​선택합니다 .


통사론

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

Parameter Description
n The index of each child to match.

Must be a number. The first element has the index number 1.
even Selects each even child element
odd Selects each odd child element
formula Specifies which child element(s) to be selected with a formula (an + b). Example: p:nth-last-child(3n+2) selects each 3rd paragraph, starting at the last 2nd child

직접 해보십시오 - 예


의 첫 번째 자식인 <p> 요소를 선택하는 방법입니다.

사용 하여
마지막 자식부터 계산하여 다른 자식 요소를 선택하는 방법.


사용 짝수 및 홀수를 사용하여 마지막 자식부터 계산하여 다른 자식 요소를 선택하는 방법.


의 차이점 p:nth-child(2), p의 차이점 :nth-last-child(2), p:nth-of-type(2) 및 p:nth-of-last-type(2).


❮ jQuery 선택기