简体   繁体   中英

I can't get li elements' index?

This is my list..

<li class="haftalar"><a value="7" class="click" href="#" title="7. Hafta Maç Özetleri">7. Hafta</a></li>
<li class="haftalar"><a value="8" class="click" href="#" title="8. Hafta Maç Özetleri">8. Hafta</a></li>

I want to get index as clicked li element's and class equaled to "haftalar".

I'm using this code but I can't get my want.

$(".click").toggle(function(){
  index = $(this).index();
}

Example -

Demo - http://jsfiddle.net/ptC7t/1/

$('.haftalar').click(function(){
    alert($('.haftalar').index($(this)));
})
$(".click").click(function(){
  index = $(".click").index(this);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM