Easiest way to sort a select element using Jquery

If you are using jquery sorting a select element is quite easy. Check the below code.

$(“#select-id”).html( $(“#select-id option”).sort(function (a, b) {
return a.text == b.text ? 0 : a.text < b.text ? -1 : 1;
}));

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.