English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery :last-of-type 선택자

jQuer 선택자

:last-of-type 선택자는 부모 요소의 특정 유형의 마지막 자식 요소를 선택할 수 있습니다.

이는 :nth-last-of-type(1와 같습니다.

사용:first-of-type선택자는 부모 요소의 특정 유형의 첫 번째 자식 요소를 선택할 수 있습니다.

문법:

$(":last-of-$("type")

예제

부모 요소의 마지막 <p> 요소를 선택하는 각 <p> 요소를 선택합니다:

$("document").ready(function(){
  $("p:last-of-type").css("background", "coral");
});
테스트를 보세요‹/›

모든 <div> 요소 내의 마지막 <p> 요소를 선택합니다:

$("document").ready(function(){
  $("div p:last-of-type").css("background", "coral");
});
테스트를 보세요‹/›

jQuer 선택자