Get index of LI in UL by index() function - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:index

Description

Get index of LI in UL by index() function

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.6.2.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*from www  .  jav  a  2  s.c  o m*/
$(function() {
    $('ul li').click(function(e) {
        console.log($(this).index());
    });
});
    });

      </script> 
 </head> 
 <body> 
  <ul> 
   <li>test 1</li> 
   <li>test 2</li> 
   <li>test 3</li> 
  </ul>  
 </body>
</html>

Related Tutorials