Get value of List Item with jQuery

后端 未结 5 977
后悔当初
后悔当初 2021-02-08 07:19

How to get value and index of list item onClick event with jQuery?
for example:

  • Item 1
  • Item 2&
5条回答
  •  遇见更好的自我
    2021-02-08 07:39

    $('ul li').click(function(){ 
         var value = $(this).text();
         var index = $('li').index($(this));
    });
    

    check this for more details

提交回复
热议问题