.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에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4856 | PHP | 7년 전 | 5730 | ||
| 4855 | jQuery | 7년 전 | 3234 | ||
| 4854 | jQuery | 7년 전 | 2225 | ||
| 4853 | jQuery | 7년 전 | 2826 | ||
| 4852 | MySQL | 7년 전 | 2993 | ||
| 4851 | jQuery | 7년 전 | 2339 | ||
| 4850 | jQuery | 7년 전 | 2569 | ||
| 4849 | jQuery | 7년 전 | 4307 | ||
| 4848 | PHP |
|
7년 전 | 4246 | |
| 4847 | jQuery | 7년 전 | 4019 | ||
| 4846 | jQuery | 7년 전 | 2631 | ||
| 4845 | jQuery | 7년 전 | 2151 | ||
| 4844 | jQuery | 7년 전 | 2299 | ||
| 4843 | jQuery | 7년 전 | 3054 | ||
| 4842 | jQuery | 7년 전 | 2898 | ||
| 4841 | jQuery | 7년 전 | 2228 | ||
| 4840 | jQuery | 7년 전 | 1565 | ||
| 4839 | jQuery | 7년 전 | 2466 | ||
| 4838 | jQuery |
이에스씨코리아
|
7년 전 | 2312 | |
| 4837 | jQuery | 7년 전 | 2161 | ||
| 4836 | jQuery | 7년 전 | 2086 | ||
| 4835 | jQuery | 7년 전 | 1819 | ||
| 4834 | jQuery | 7년 전 | 1865 | ||
| 4833 | jQuery | 7년 전 | 1992 | ||
| 4832 | jQuery | 7년 전 | 2183 | ||
| 4831 | jQuery | 7년 전 | 2362 | ||
| 4830 | jQuery | 7년 전 | 2629 | ||
| 4829 | jQuery | 7년 전 | 1802 | ||
| 4828 | jQuery | 8년 전 | 2744 | ||
| 4827 | jQuery | 8년 전 | 2282 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기