Skip to content

Instantly share code, notes, and snippets.

@prio101
Created April 10, 2025 10:36
Show Gist options
  • Save prio101/65044455c2d5ca1ef02fa248d5516bee to your computer and use it in GitHub Desktop.
Save prio101/65044455c2d5ca1ef02fa248d5516bee to your computer and use it in GitHub Desktop.
const select = document.getElementById("current_currency");
const options = Array.from(select.options);
// Remove and sort options
const sortedOptions = options.sort((a, b) => {
return a.text.localeCompare(b.text);
});
// Clear existing options and re-add sorted ones
select.innerHTML = "";
sortedOptions.forEach(option => select.appendChild(option));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment