Created
April 3, 2013 19:29
-
-
Save jookyboi/5304487 to your computer and use it in GitHub Desktop.
Sort Javascript elements from http://stackoverflow.com/questions/304396/what-is-the-easiest-way-to-order-a-ul-ol-in-jquery
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
var items = $('.alphaList li').get(); | |
items.sort(function(a,b){ | |
var keyA = $(a).text(); | |
var keyB = $(b).text(); | |
if (keyA < keyB) return -1; | |
if (keyA > keyB) return 1; | |
return 0; | |
}); | |
var ul = $('.alphaList'); | |
$.each(items, function(i, li){ | |
ul.append(li); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment