Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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');
Comment

PREVIOUS NEXT
Code Example
Javascript :: react router get host origin js 
Javascript :: passport.initialize() middleware not in use 
Javascript :: upload file using ajax 
Javascript :: how to disable right click in javascript 
Javascript :: javascript select random element from array 
Javascript :: javascript timestamp to relative time 
Javascript :: open a new tab when clicking on a link react 
Javascript :: mongodb delete user 
Javascript :: javascript round to 2 decimal places 
Javascript :: autherization token in axios 
Javascript :: regex expression dd/mm/yyyy javascript 
Javascript :: how to upgrade to react 18 
Javascript :: string iterate in js 
Javascript :: sequelize pagination postgres 
Javascript :: how to empty an element in javascript 
Javascript :: js check if value is not empty string 
Javascript :: PayloadTooLargeError: request entity too large 
Javascript :: load jquery in the browser code 
Javascript :: golang convert json string to map 
Javascript :: validators.pattern angular number 
Javascript :: jquery validation on button click 
Javascript :: ref schemas mongoose error 
Javascript :: js add value to html input 
Javascript :: html loop through array 
Javascript :: js foreach determine if last 
Javascript :: Hide elements until Alpine Js loads 
Javascript :: import jqueery vanilla js 
Javascript :: page redirect after a few seconds 
Javascript :: javascript assign value to input using name 
Javascript :: nest js doesnt recognize changes 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =