Skip to content

Instantly share code, notes, and snippets.

@betovelandia
Created August 23, 2012 22:36
Show Gist options
  • Select an option

  • Save betovelandia/3442855 to your computer and use it in GitHub Desktop.

Select an option

Save betovelandia/3442855 to your computer and use it in GitHub Desktop.
Order List Alphabetically
function orderSelect($element) {
var options = $element.find('option'),
n_options = options.length,
temp = [],
parts,
i;
for(i = n_options; i --;) {
temp[i] = options[i].text + "," + options[i].value ;
}
temp.sort();
for(i = n_options; i --;) {
parts = temp[i].split(',');
options[i].text = parts[0];
options[i].value = parts[1];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment