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 December 5, 2023 06:54
[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 );