jquery sort select options by text

Solutions on MaxInterview for jquery sort select options by text by the best coders in the world

showing results for - "jquery sort select options by text"
Gabriele
29 Feb 2020
1function alphabetizeList() {
2    var sel = $(listField);
3    var selected = sel.val(); // cache selected value, before reordering
4    var opts_list = sel.find('option');
5    opts_list.sort(function (a, b) {
6        return $(a).text() > $(b).text() ? 1 : -1;
7    });
8    sel.html('').append(opts_list);
9    sel.val(selected); // set cached selected value
10}
11
12alphabetizeList('#FIELDID');
queries leading to this page
arrange item in selectfor option sort jqueryhtml select option alphabetical orderjquery sort items in select optionhow to insert option into select keeping ascending ordersort select option alphabetically in javascriptjavascript jquery order a selectselect box option sort alphabeticallyjquery sort select optionsjquery add option to select in orderjquery order select options by valuesort dropdown alphabetically jqueryjquery select orderingsort option list jqueryjquery sort dropdown alphabeticallyjquery sort options by textsort options in select alphabeticallyjquery multiselect dropdown alphabetic sortsort element by option valuejquery order up select optionsmultiselect dropdown with alphabet sort jssort select options alphabetically javascripthtml combobox sort alphabeticallyset select option orderhtml select order alphabeticallysort select box alphabetically javascriptjquery alphabetize select optionssorting select options jqueryjavascript select order alphabeticallydropdown search jquery by alphabeticalhow to set order to dropdown in jqueryjquery sort select options by textsort all dropdown alphabetically jqueryjquery sort select options by valuearrange select list a to z jquerysortable drop down list jqueryjquery order select options alphabeticallybjquery organize optionsordering alphabetically select box htmlhtml select option alphabetical order automaticallyselect option alphabetical ordersort dropdown box jqueryjquery sort options in selectjavascript sort select options alphabeticallyjquery sort select options by text