jQuery :nth-of-type() 선택기

❮ jQuery 선택기

예시

부모의 세 번째 <p> 요소인 각 <p> 요소를 선택합니다.

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

정의 및 사용

:nth-of-type( n ) 선택기는 특정 유형의 상위 n 번째 하위 요소인 모든 요소를 ​​선택합니다 .

팁: :nth-child() 선택기를 사용 하여 부모 의 유형에 관계없이 n 번째 자식인 모든 요소를 ​​선택합니다 .


통사론

:nth-of-type(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-of-type(3n+2) selects each 3rd paragraph, starting at the 2nd paragraph

직접 해보십시오 - 예


각 <p> 요소를 선택하는 방법입니다.


수식( an + b )을 사용하여 다른 자식 요소를 선택하는 방법.


사용 짝수 및 홀수를 사용하여 다른 자식 요소를 선택하는 방법.


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


❮ jQuery 선택기