• 회원가입
  • 로그인
  • 구글아이디로 로그인

[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>

 

결과보기

 

방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
Selector JQ - [attribute != value] 속성선택자 - 지정 속성값 아닌 요소 선택.
Selector JQ - [attribute$=value] 속성선택자 - 지정 문자열로 끝나는 속성값 갖는 요소 선택.
Selector JQ - [attribute|=value] 속성선택자 - 지정 문자열 또는 뒤에 하이픈 연결된 속성값 갖는 …
Selector JQ - [attribute^=value] 속성선택자 - 지정 문자열로 시작하는 모든 요소 선택. (= 시작…
Selector JQ - [attribute~=value] 속성선택자 - 특정 속성값 또는 그 앞뒤 공백인 요소 선택.
Selector JQ - [attribute*=value] 속성선택자 - 지정 문자열 포함 속성값 갖는 요소 선택.
Selector JQ - :input 선택자 - input, button 요소 선택. (= 인풋 선택자)
Selector JQ - :text 선택자 - type="text"인 input 요소 선택. (= 텍스트선택자/타입선택자)
Selector JQ - :password 선택자 - type="password"인 input 요소 선택. (= 패스워드 선…
Selector JQ - :radio 선택자 - type="radio"인 input 요소 선택. (= 라디오 선택자)
Selector JQ - :checkbox 선택자 - type="checkbox"인 input 요소 선택 (= 체크박스선택자…
Selector JQ - :submit 선택자 - type="submit"인 input, button 요소 선택. (= 서브…
Selector JQ - :reset 선택자 - type="reset"인 input, button 요소 선택. (= 리셋 선…
Selector JQ - :button 선택자 - type="button"인 input, button 요소 선택. (= 버튼…
Selector JQ - :image 선택자 - type="image"인 input 요소 선택. (= 이미지 선택자)
Selector JQ - :file 선택자 - type="file"인 input 요소 선택. (= 파일 선택자)
Selector JQ - :enabled 선택자 - 활성화 된 요소 선택. (= 인에이블드 선택자)
Selector JQ - :disabled 선택자 - 비활성화 된 요소 선택. (= 디서에이블드 선택자)
Selector JQ - :selected 선택자 - selected="selected"인 요소 선택. (= 실렉티드 선택자…
Selector JQ - :checked 선택자 - $(":checked") - checked="checked"인 모든 체크…
5/15
목록
찾아주셔서 감사합니다. Since 2012