Skip to content

Instantly share code, notes, and snippets.

@mc-stephen
Forked from cschlyter/sortSelectOption.js
Created July 1, 2021 00:43
Show Gist options
  • Select an option

  • Save mc-stephen/b3c7a220321dd75f189e49db0f81d18a to your computer and use it in GitHub Desktop.

Select an option

Save mc-stephen/b3c7a220321dd75f189e49db0f81d18a to your computer and use it in GitHub Desktop.

Revisions

  1. @cschlyter cschlyter revised this gist Mar 21, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions sortSelectOption.js
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,8 @@ function sortSelectOptions(selectElement) {
    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
    })
    else return 0;
    });

    $(selectElement).empty().append( options );
    }
  2. @cschlyter cschlyter renamed this gist Mar 18, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @cschlyter cschlyter created this gist Mar 18, 2013.
    11 changes: 11 additions & 0 deletions sortSelectOption
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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 );
    }