0

var options = jQuery('select#states option');
var arr = options.map(function(_, o) { return { t: jQuery(o).text(), v: o.value }; }).get();
arr.sort(function(o1, o2) { return o1.t > o2.t ? 1 : o1.t < o2.t ? -1 : 0; });
options.each(function(i, o) {
  o.value = arr[i].v;
  jQuery(o).text(arr[i].t);
});

Jagdish Sarma Asked question October 14, 2020
Add a Comment