Posted By

smashu on 04/23/10


Tagged

sort list jquery alphabetically


Versions (?)

Jquery sort list alphabetically


 / Published in: JavaScript
 

  1. var mylist = $('ul');
  2. var listitems = mylist.children('li').get();
  3. listitems.sort(function(a, b) {
  4. var compA = $(a).text().toUpperCase();
  5. var compB = $(b).text().toUpperCase();
  6. return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
  7. })
  8. $.each(listitems, function(idx, itm) { mylist.append(itm); });

Report this snippet  

You need to login to post a comment.