Get index of clicked element in collection with jQuery - Javascript jQuery

Javascript examples for jQuery:Mouse Event

Description

Get index of clicked element in collection with jQuery

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.5.2.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*w  w  w  .  ja  v a2s .  c  o m*/
$('li').click(function (event) {
    console.log($(this).index());
});
    });

      </script> 
 </head> 
 <body> 
  <li>Test</li> 
  <li>Test</li> 
  <li>Test</li> 
  <li>Test</li> 
  <li>Test</li>  
 </body>
</html>

Related Tutorials