/ Published in: JavaScript

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var mylist = $('ul'); var listitems = mylist.children('li').get(); listitems.sort(function(a, b) { var compA = $(a).text().toUpperCase(); var compB = $(b).text().toUpperCase(); return (compA < compB) ? -1 : (compA > compB) ? 1 : 0; }) $.each(listitems, function(idx, itm) { mylist.append(itm); });
Comments
