Skip to content

Instantly share code, notes, and snippets.

View rlapenda's full-sized avatar

Rodrigo Lapenda rlapenda

View GitHub Profile
@cschlyter
cschlyter / sortSelectOption.js
Last active October 2, 2024 10:05
[Javascript] Sort alphabetically the option elements of a select element by text.
function sortSelectOptions(selectElement) {
var options = $(selectElement + " option");
options.sort(function(a,b) {
if (a.text.toUpperCase() > b.text.toUpperCase()) return 1;
else if (a.text.toUpperCase() < b.text.toUpperCase()) return -1;
else return 0;
});
$(selectElement).empty().append( options );