jQuery

[Selector] JQ - :last-of-type 가상선택자 - 타입 고려 마지막 자식요소 선택. (= 라스트 어브 타입 선택자)

목차
  1. :last-of-type 예제 - 그 부모의 타입 고려 마지막 자식p요소.
  2. :last-of-type 정의
  3. :last-of-type 구문
  4. :last-of-type 예제 - div의 타입 고려 마지막 자식p요소.
  5. :last-of-type 예제 - cf. :last, :last-child

 

:last-of-type 예제 - 그 부모의 타입 고려 마지막 자식p요소.

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

  $("p:last-of-type").css("background-color", "yellow");

});

</script>


<p>홈짱닷컴 Homzzang.com</p>

<div style="border:1px solid;">

  <p>HTML</p>

  <p>구조</p>

</div><br>

<div style="border:1px solid;">

  <p>CSS</p>

  <p>디자인</p>

  <span>구조 보충</span>

</div>

<p>홈페이지 제작관리 강의</p>

 

결과보기

 

:last-of-type 정의

 

그 부모의 타입 고려 마지막 자식요소 선택.

 


 

1.

:nth-last-of-type(1) 선택자와 동일.

 

2.

:first-of-type 선택자 : 그 부모의 타입 고려 첫번째 자식요소.

 

 

:last-of-type 구문

 

$(":last-of-type")

 

 

:last-of-type 예제 - div의 타입 고려 마지막 자식p 요소.

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

  $("div p:last-of-type").css("background-color", "yellow");

});

</script>


<p>홈짱닷컴 Homzzang.com</p>

<div style="border:1px solid;">

  <p>HTML</p>

  <p>구조</p>

</div><br>

<div style="border:1px solid;">

  <p>CSS</p>

  <p>디자인</p>

  <span>구조 보충</span>

</div>

<p>홈페이지 제작관리 강의</p>

 

결과보기

 

:last-of-type 예제 - cf. :last, :last-child

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

  $("button").click(function(){

    var btn = $(this).text();

    $("p").css("background-color", "white"); 

    $("p" + btn).css("background-color", "yellow"); 

  });

});

</script>


<button>:last</button>

<button>:last-child</button>

<button>:last-of-type</button><br>


<p>홈짱닷컴 Homzzang.com</p>

<div style="border:1px solid;">

  <p>HTML</p>

  <p>구조</p>

</div><br>

<div style="border:1px solid;">

  <span>CSS</span>

  <p>다지인</p>

  <p>구조보충</p>

  <span>인라인스타일, 내부스타일, 외부스타일</span>

</div><br>

<div style="border:1px solid">

  <p>JS</p>

  <p>동적기능</p>

</div>

<p>홈페이지 제작관리 강의</p>

 

결과보기

 


분류 제목
Selector JQ - selector ★★★★★ - 선택자 (= 제어할 요소선택) ※ this선택자 (=디스선택자)
Selector JQ - * 선택자 - 모든 요소 선택. (= 전체선택자 = 전체 요소선택자 = 아스테리크 선택자)
Selector JQ - #id 선택자 - 지정 아이디 갖는 요소 선택. (= 아이디 선택자)
Selector JQ - .class 선택자 - 지정 클래스 갖는 요소 선택. (= 클래스 선택자)
Selector JQ - element 선택자 - 지정 요소 모두 선택. (= 요소선택자)
Selector JQ - e1,e2,e3... 선택자 - 여러 요소 선택. (= 여러 요소선택자)
Selector JQ - :first 가상선택자 - 가장 첫번째 지정요소 선택. (= 맨 처음 요소 선택 = 퍼스트 선택자)
Selector JQ - :last 가상선택자 - 가장 마지막 지정 요소 선택. (= 맨뒤 요소 선택 = 라스트 선택자)
Selector JQ - :even 가상선택자 - 짝수 번째 요소 선택. (= 이븐 선텍자)
Selector JQ - :odd 가상선택자 - 홀수 번째 요소 선택. (= 아드 선택자)
Selector JQ - :first-child 가상선택자 - 첫번째 자식요소 선택. (= 퍼스트 차일드 선택자)
Selector JQ - :first-of-type 가상선택자 - 타입 고려 첫번째 자식요소 선택. (= :first-of-…
Selector JQ - :last-child 가상선택자 - 마지막 자식요소 선택. (= 라스트 차일드 선택자)
Selector JQ - :last-of-type 가상선택자 - 타입 고려 마지막 자식요소 선택. (= 라스트 어브 타입 선…
Selector JQ - :nth-child(n) 가상선택자 - 타입 무관 n번째 자식요소 모두 선택. (= nth-chil…
1/5
목록
 홈  PC버전 로그인 일본어
그누앞단언어 1
그누뒷단언어
그외코딩언어
그누보드
제작의뢰
Q&A
커뮤니티 1
웹유틸
회원센터
홈짱닷컴 PC버전 로그인