Get id from each li - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:each

Description

Get id from each li

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-2.2.0.min.js"></script> 
  <script type="text/javascript">
    window.onload=function(){/*from  www.ja  va2s.co m*/
    $('.test').on('click', 'li', function(event){
        console.log($(event.target).attr('id'));
    });
    }

      </script> 
 </head> 
 <body> 
  <ul id="3" class="test"> 
   <li id="2">aca2</li> 
   <li id="1">aca</li> 
  </ul>  
 </body>
</html>

Related Tutorials