Skip to content

Instantly share code, notes, and snippets.

@Granze
Created March 25, 2012 22:32
Show Gist options
  • Select an option

  • Save Granze/2200442 to your computer and use it in GitHub Desktop.

Select an option

Save Granze/2200442 to your computer and use it in GitHub Desktop.
A-Z order <ul> items
var items = $('.to_order 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 = $('.to_order');
$.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