jquery sort select options by text

function alphabetizeList() {
    var sel = $(listField);
    var selected = sel.val(); // cache selected value, before reordering
    var opts_list = sel.find('option');
    opts_list.sort(function (a, b) {
        return $(a).text() > $(b).text() ? 1 : -1;
    });
    sel.html('').append(opts_list);
    sel.val(selected); // set cached selected value
}

alphabetizeList('#FIELDID');

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
jquery sort options by text ordering alphabetically select box html jquery sort dropdown alphabetically jquery select ordering select option alphabetical order arrange item in select sortable drop down list jquery dropdown search jquery by alphabetical sort option list jquery set select option order sort dropdown box jquery sort element by option value for option sort jquery how to insert option into select keeping ascending order jquery add option to select in order html select option alphabetical order automatically html select option alphabetical order sort select option alphabetically in javascript sort options in select alphabetically html select order alphabetically sort all dropdown alphabetically jquery sort dropdown alphabetically jquery multiselect dropdown with alphabet sort js jquery multiselect dropdown alphabetic sort arrange select list a to z jquery select box option sort alphabetically javascript select order alphabetically sort select box alphabetically javascript jquery sort items in select option javascript sort select options alphabetically bjquery organize options jquery order up select options sorting select options jquery html combobox sort alphabetically how to set order to dropdown in jquery jquery sort select options jquery alphabetize select options sort select options alphabetically javascript jquery order select options alphabetically jquery sort options in select jquery order select options by value javascript jquery order a select jquery sort select options by text
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source