Order a list of names alphabetically - Javascript jQuery

Javascript examples for jQuery:List

Description

Order a list of names alphabetically

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(){/*  ww w .j  a v  a  2s . c  om*/
var items = [];
$('ul li').each(function(){
   items.push($(this).html());
})
items.sort();
console.log(items)
    });

      </script> 
 </head> 
 <body> 
  <ul> 
   <li>M</li> 
   <li>J</li> 
  </ul>  
 </body>
</html>

Related Tutorials