Live Brilliant

li 태그 index 값 출력 본문

개발은 핵찜이야/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>


'개발은 핵찜이야 > JQUERY' 카테고리의 다른 글

jquery settimeout redirect  (0) 2013.06.05
jquery mobile data-ajax false[페이지 전환 문제 해결]  (0) 2013.05.31
jquery scroll 사용법  (0) 2013.05.28
[JQuery] Ajax load  (0) 2012.07.05
[JQuery] Custom function  (0) 2012.07.05
Comments