Looping through li elements adding a z-index and incrementing value on each - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:each

Description

Looping through li elements adding a z-index and incrementing value on each

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  ww .j av a  2  s  .c  om*/
$('li').each(function(index) {
    $(this).css('z-index', index);
});
    });

      </script> 
 </head> 
 <body> 
  <ul> 
   <li>A</li> 
   <li>B</li> 
   <li>C</li> 
   <li>D</li> 
  </ul>  
 </body>
</html>

Related Tutorials