개발은 핵찜이야/JQUERY
li 태그 index 값 출력
주인정
2012. 11. 21. 21:33
* li 태그 클릭시 li 인덱스값 추출
클릭한 li 태그가 몇번째인지 알고 싶을때
<!DOCTYPE html>
<html>
<head>
<script src="jquery.js"></script>
<script>
$(document).ready(function(){
$('li').click(function(index) {
alert(index + ': ' + $('li').index(this));
});
});
</script>
</head>
<body>
<h1>Welcome to My Homepage</h1>
<p class="intro">My name is Donald</p>
<p>I live in Duckburg</p>
<p>My best friend is Mickey</p>
<ul id="choose">
<li>Goofy</li>
<li>Mickey</li>
<li>Pluto</li>
</ul>
</body>
</html>