.get (index)
.get (index)
설명 : jQuery 객체와 일치하는 요소 중 하나를 검색하십시오.
이 .get()메소드는 각 jQuery 객체의 기본 DOM 노드에 대한 액세스를 허용합니다. 의 값이 index범위를 벗어나는 경우 - 음의 요소 수보다 작거나 요소 수보다 크거나 같으면 반환합니다 undefined. 순서가없는 간단한 목록을 생각해보십시오.
<ul>
<li id="foo">foo</li>
<li id="bar">bar</li>
</ul>
인덱스를 지정 .get( index )하면 단일 요소를 검색합니다.
console.log( $( "li" ).get( 0 ) );
인덱스는 0부터 시작하므로 첫 번째 목록 항목이 반환됩니다.
<li id = "foo">
또한 각 jQuery 객체는 배열로 위장하므로 배열 역 참조 연산자를 사용하여 목록 항목을 대신 얻을 수 있습니다.
console.log( $( "li" )[ 0 ] );
그러나이 구문에는 음수 인덱스 지정과 같은 .get ()의 추가 기능이 없습니다.
console.log( $( "li" ).get( -1 ) );
음수 인덱스는 일치하는 집합의 끝에서부터 계산되므로이 예제는 목록의 마지막 항목을 반환합니다.
<li id = "bar">
예:
클릭 요소의 태그 이름을 표시합니다.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>get demo</title>
<style>
span {
color: red;
}
div {
background: yellow;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<span> </span>
<p>In this paragraph is an <span>important</span> section</p>
<div><input type="text"></div>
<script>
$( "*", document.body ).click(function( event ) {
event.stopPropagation();
var domElement = $( this ).get( 0 );
$( "span:first" ).text( "Clicked on - " + domElement.nodeName );
});
</script>
</body>
</html>
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4946 | node.js | 6년 전 | 2606 | ||
| 4945 | node.js | 6년 전 | 2379 | ||
| 4944 | node.js | 6년 전 | 2519 | ||
| 4943 | node.js | 6년 전 | 2269 | ||
| 4942 | node.js | 6년 전 | 2244 | ||
| 4941 | node.js | 6년 전 | 2717 | ||
| 4940 | node.js | 6년 전 | 1867 | ||
| 4939 | node.js | 6년 전 | 1995 | ||
| 4938 | node.js | 6년 전 | 2457 | ||
| 4937 | node.js | 6년 전 | 2247 | ||
| 4936 | node.js | 6년 전 | 2318 | ||
| 4935 | node.js | 6년 전 | 2136 | ||
| 4934 | node.js | 6년 전 | 2440 | ||
| 4933 | node.js | 6년 전 | 2244 | ||
| 4932 | node.js | 6년 전 | 2685 | ||
| 4931 | node.js | 6년 전 | 2070 | ||
| 4930 | node.js | 6년 전 | 1998 | ||
| 4929 | node.js | 6년 전 | 8629 | ||
| 4928 | node.js | 6년 전 | 3749 | ||
| 4927 | node.js | 6년 전 | 2391 | ||
| 4926 | node.js | 6년 전 | 2504 | ||
| 4925 | node.js | 6년 전 | 2081 | ||
| 4924 | node.js | 6년 전 | 3371 | ||
| 4923 | node.js | 6년 전 | 2220 | ||
| 4922 | node.js | 6년 전 | 1989 | ||
| 4921 | node.js | 6년 전 | 2046 | ||
| 4920 | node.js | 6년 전 | 1763 | ||
| 4919 | node.js | 6년 전 | 2028 | ||
| 4918 | node.js | 6년 전 | 2176 | ||
| 4917 | node.js | 6년 전 | 2393 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기