jQuery ( ": first-of-type")

· 8년 전 · 1487

jQuery ( ": first-of-type")


설명 : 동일한 요소 이름의 형제 중 첫 번째 요소를 모두 선택합니다.


:first-of-type선택은 같은 부모와 문서 트리에 전에 오는 같은 요소 이름 모두 다른 요소가없는 요소를 일치합니다.


예:

일치하는 각 div에서 첫 번째 범위를 찾아 클래스를 추가하십시오.


<!doctype html>

<html lang="en">

<head>

  <meta charset="utf-8">

  <title>first-of-type demo</title>

  <style>

  span.fot {

    color: red;

    font-size: 120%;

    font-style: italic;

  }

  </style>

  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>

</head>

<body>

 

<div>

  <span>Corey,</span>

  <span>Yehuda,</span>

  <span>Adam,</span>

  <span>Todd</span>

</div>

<div>

  <b>Nobody,</b>

  <span>Jörn,</span>

  <span>Scott,</span>

  <span>Timo</span>

</div>

 

<script>

$( "span:first-of-type" ).addClass( "fot" );

</script>

 

</body>

</html>

|
댓글을 작성하시려면 로그인이 필요합니다. 로그인

개발자팁

개발과 관련된 유용한 정보를 공유하세요. 질문은 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
jQuery
[jQuery]
8년 전 조회 1,560
jQuery 8년 전 조회 1,733
jQuery 8년 전 조회 1,836
PHP 8년 전 조회 5,157
node.js 8년 전 조회 4,158
jQuery 8년 전 조회 2,230
jQuery 8년 전 조회 1,672
jQuery 8년 전 조회 1,225
jQuery 8년 전 조회 1,946
jQuery 8년 전 조회 1,448
jQuery 8년 전 조회 1,559
jQuery 8년 전 조회 1,782
jQuery 8년 전 조회 2,016
jQuery 8년 전 조회 1,553
jQuery 8년 전 조회 1,488
jQuery 8년 전 조회 1,580
jQuery
[jQuery]
8년 전 조회 1,465
jQuery 8년 전 조회 1,592
jQuery 8년 전 조회 1,640
jQuery 8년 전 조회 1,657
jQuery 8년 전 조회 1,840
jQuery 8년 전 조회 1,772
jQuery 8년 전 조회 1,635
jQuery 8년 전 조회 1,705
jQuery 8년 전 조회 1,501
jQuery
[jQuery]
8년 전 조회 1,466
jQuery
[jQuery]
8년 전 조회 1,667
jQuery 8년 전 조회 1,554
jQuery 8년 전 조회 1,250
jQuery 8년 전 조회 1,625
🐛 버그신고