.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에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4736 | jQuery | 8년 전 | 1559 | ||
| 4735 | jQuery | 8년 전 | 1747 | ||
| 4734 | jQuery | 8년 전 | 1737 | ||
| 4733 | jQuery | 8년 전 | 2032 | ||
| 4732 | jQuery | 8년 전 | 1955 | ||
| 4731 | jQuery | 8년 전 | 1459 | ||
| 4730 | jQuery | 8년 전 | 1917 | ||
| 4729 | PHP |
|
8년 전 | 6898 | |
| 4728 | jQuery | 8년 전 | 2562 | ||
| 4727 | jQuery | 8년 전 | 1610 | ||
| 4726 | jQuery | 8년 전 | 1689 | ||
| 4725 | jQuery | 8년 전 | 1834 | ||
| 4724 | jQuery | 8년 전 | 1310 | ||
| 4723 | jQuery | 8년 전 | 1862 | ||
| 4722 | jQuery | 8년 전 | 1625 | ||
| 4721 | jQuery | 8년 전 | 1917 | ||
| 4720 | jQuery | 8년 전 | 1974 | ||
| 4719 | jQuery | 8년 전 | 1601 | ||
| 4718 | jQuery | 8년 전 | 1607 | ||
| 4717 | jQuery | 8년 전 | 1558 | ||
| 4716 | jQuery | 8년 전 | 1236 | ||
| 4715 | jQuery | 8년 전 | 1394 | ||
| 4714 | jQuery | 8년 전 | 1415 | ||
| 4713 | jQuery | 8년 전 | 1334 | ||
| 4712 | jQuery | 8년 전 | 2227 | ||
| 4711 | jQuery | 8년 전 | 1711 | ||
| 4710 | PHP |
|
8년 전 | 3747 | |
| 4709 | jQuery | 8년 전 | 1629 | ||
| 4708 | jQuery | 8년 전 | 1909 | ||
| 4707 | jQuery | 8년 전 | 1760 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기