반응형
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>index demo</title>
<style>
div {
background: yellow;
margin: 5px;
}
span {
color: red;
}
</style>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>
<body>
<span>Click a div!</span>
<div>First div</div>
<div>Second div</div>
<div>Third div</div>
<script>
$("div").click(function() {
// `this` is the DOM element that was clicked
var index = $("div").index(this);
$("span").text("That was div index #" + index);
});
</script>
</body>
</html>
반응형
'2020 > JQuery' 카테고리의 다른 글
JQuery 현재요소, 다음요소, next(), nextAll() (0) | 2020.03.06 |
---|---|
jquery animation stop (0) | 2020.03.06 |
JQuery height, width (0) | 2020.03.05 |
JQuery prop, 체크박스 전체 선택, 전체 해제 (0) | 2020.03.05 |
Jquery focus, blur, focusin, focusout (0) | 2020.03.05 |