JQuery .each() to set <LI> element text - Javascript jQuery

Javascript examples for jQuery:Select Dropdown

Description

JQuery .each() to set <LI> element text

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.9.1.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*from  w w  w. ja  v a2s. c o  m*/
var $li = $("ul > li");
$li.each(function (i) {
    $(this).text('Item ' + ($li.length - i));
});
    });

      </script> 
 </head> 
 <body> 
  <ul> 
   <li>Item 1</li> 
   <li>Item 2</li> 
   <li>Item 3</li> 
   <li>Item 4</li> 
   <li>Item 5</li> 
  </ul>  
 </body>
</html>

Related Tutorials