.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에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4706 | jQuery | 8년 전 | 1517 | ||
| 4705 | jQuery | 8년 전 | 2180 | ||
| 4704 | jQuery | 8년 전 | 1712 | ||
| 4703 | jQuery | 8년 전 | 2048 | ||
| 4702 | jQuery | 8년 전 | 1837 | ||
| 4701 | jQuery | 8년 전 | 2071 | ||
| 4700 | jQuery | 8년 전 | 1750 | ||
| 4699 | jQuery | 8년 전 | 1532 | ||
| 4698 | jQuery | 8년 전 | 1340 | ||
| 4697 | jQuery | 8년 전 | 1755 | ||
| 4696 | jQuery | 8년 전 | 2375 | ||
| 4695 | jQuery | 8년 전 | 1391 | ||
| 4694 | jQuery | 8년 전 | 1804 | ||
| 4693 | jQuery | 8년 전 | 1779 | ||
| 4692 | jQuery | 8년 전 | 2573 | ||
| 4691 | jQuery | 8년 전 | 2080 | ||
| 4690 | jQuery | 8년 전 | 1970 | ||
| 4689 | jQuery | 8년 전 | 1950 | ||
| 4688 | jQuery | 8년 전 | 1708 | ||
| 4687 | jQuery | 8년 전 | 1120 | ||
| 4686 | jQuery | 8년 전 | 1753 | ||
| 4685 | jQuery | 8년 전 | 2497 | ||
| 4684 | jQuery | 8년 전 | 2377 | ||
| 4683 | jQuery | 8년 전 | 1772 | ||
| 4682 | PHP | 8년 전 | 3094 | ||
| 4681 | jQuery | 8년 전 | 1611 | ||
| 4680 | jQuery | 8년 전 | 1800 | ||
| 4679 | PHP | 8년 전 | 2026 | ||
| 4678 | PHP | 8년 전 | 2158 | ||
| 4677 | PHP | 8년 전 | 2260 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기