jQuery ( ": first-of-type") 정보
jQuery jQuery ( ": first-of-type")본문
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>
추천
0
0
댓글 0개