.first()
.first()
설명 : 일치하는 요소 집합을 집합의 첫 번째 집합으로 줄입니다.
DOM 요소 집합을 나타내는 jQuery 객체가 주어지면이 .first()메서드는 해당 집합의 첫 번째 요소에서 새 jQuery 객체를 생성합니다.
간단한 목록이있는 페이지를 고려해보십시오.
<ul>
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
<li>list item 4</li>
<li>list item 5</li>
</ul>
이 메소드를 목록 항목 집합에 적용 할 수 있습니다.
$( "li" ).first().css( "background-color", "red" );
이 호출의 결과는 첫 번째 항목에 대한 빨간색 배경입니다.
예:
단락의 첫 번째 범위를 강조 표시하십시오.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>first demo</title>
<style>
.highlight{
background-color: yellow
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<p>
<span>Look:</span>
<span>This is some text in a paragraph.</span>
<span>This is a note about it.</span>
</p>
<script>
$( "p span" ).first().addClass( "highlight" );
</script>
</body>
</html>
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4946 | node.js | 6년 전 | 2614 | ||
| 4945 | node.js | 6년 전 | 2387 | ||
| 4944 | node.js | 6년 전 | 2524 | ||
| 4943 | node.js | 6년 전 | 2276 | ||
| 4942 | node.js | 6년 전 | 2256 | ||
| 4941 | node.js | 6년 전 | 2723 | ||
| 4940 | node.js | 6년 전 | 1869 | ||
| 4939 | node.js | 6년 전 | 1996 | ||
| 4938 | node.js | 6년 전 | 2460 | ||
| 4937 | node.js | 6년 전 | 2253 | ||
| 4936 | node.js | 6년 전 | 2326 | ||
| 4935 | node.js | 6년 전 | 2139 | ||
| 4934 | node.js | 6년 전 | 2447 | ||
| 4933 | node.js | 6년 전 | 2250 | ||
| 4932 | node.js | 6년 전 | 2690 | ||
| 4931 | node.js | 6년 전 | 2073 | ||
| 4930 | node.js | 6년 전 | 2000 | ||
| 4929 | node.js | 6년 전 | 8637 | ||
| 4928 | node.js | 6년 전 | 3754 | ||
| 4927 | node.js | 6년 전 | 2397 | ||
| 4926 | node.js | 6년 전 | 2507 | ||
| 4925 | node.js | 6년 전 | 2088 | ||
| 4924 | node.js | 6년 전 | 3376 | ||
| 4923 | node.js | 6년 전 | 2225 | ||
| 4922 | node.js | 6년 전 | 1995 | ||
| 4921 | node.js | 6년 전 | 2049 | ||
| 4920 | node.js | 6년 전 | 1768 | ||
| 4919 | node.js | 6년 전 | 2034 | ||
| 4918 | node.js | 6년 전 | 2182 | ||
| 4917 | node.js | 6년 전 | 2398 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기