Skip to content

Instantly share code, notes, and snippets.

@estruyf
Last active August 29, 2015 14:09
Show Gist options
  • Save estruyf/37716172783d40f11ebe to your computer and use it in GitHub Desktop.
Save estruyf/37716172783d40f11ebe to your computer and use it in GitHub Desktop.
/* Long Version */
$(".list li").sort(asc_sort).appendTo('.list');
// ascending sort
function asc_sort(a, b){
return ($(b).text().toUpperCase()) < ($(a).text().toUpperCase()) ? 1 : -1;
}
// descending sort
function desc_sort(a, b){
return ($(b).text().toUpperCase()) > ($(a).text().toUpperCase()) ? 1 : -1;
}
/* Short Version */
$(".list li").sort(function(a, b){
return ($(b).text().toUpperCase()) < ($(a).text().toUpperCase()) ? 1 : -1;
}).appendTo('.list');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment