Last active
          January 4, 2016 03:19 
        
      - 
      
- 
        Save quawn/8560762 to your computer and use it in GitHub Desktop. 
    JS: Sort a list alphabetically
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | $(function() { | |
| $.fn.sortList = function() { | |
| var mylist = $(this); | |
| var listitems = $('li', mylist).get(); | |
| listitems.sort(function(a, b) { | |
| var compA = $(a).text().toUpperCase(); | |
| var compB = $(b).text().toUpperCase(); | |
| return (compA < compB) ? -1 : 1; | |
| }); | |
| $.each(listitems, function(i, itm) { | |
| mylist.append(itm); | |
| }); | |
| } | |
| $("ul#demoOne").sortList(); | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment