I have the following code to sort the items in a dropdown list:
function sortDropDownListByText(selectId) {
$(selectId).html($(selectId + \" option\").so
How about always returning -1
for that item?
$(selectId).html($(selectId + " option").sort(function(a, b) {
return a.text == "Please select an item from the list" ? -1 : a.text < b.text ? -1 : 1;
});
more dynamically:
$(selectId).html($(selectId + " option").sort(function(a, b) {
return a.text == $(selectId + 'option:first').text ? -1 : a.text < b.text ? -1 : 1;
});