Skip to content

Instantly share code, notes, and snippets.

@ericclemmons
Created February 15, 2010 21:56
Show Gist options
  • Save ericclemmons/305035 to your computer and use it in GitHub Desktop.
Save ericclemmons/305035 to your computer and use it in GitHub Desktop.
Sort a SELECT box's OPTIONs alphabetically
var SortSelect = function(select) {
var options = jQuery.makeArray(select.find('option'));
var sorted = options.sort(function(a, b) {
return (jQuery(a).text() > jQuery(b).text()) ? 1 : -1;
});
select.append(jQuery(sorted))
.attr('selectedIndex', 0);
};
@jszuluagam
Copy link

$(a).text().toLowerCase().localeCompare($(b).text().toLowerCase())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment