Home > Open Source, Technology > Easiest way to sort a select element using Jquery

Easiest way to sort a select element using Jquery

If you are using jquery sorting a select element is quite easy. Check the below code.

$(“#select-id”).html( $(“#select-id option”).sort(function (a, b) {
return a.text == b.text ? 0 : a.text < b.text ? -1 : 1;
}));

  1. No comments yet.
Submitting Comment, Give me a second...

Leave a comment

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackbacks & Pingbacks ( 0 )
  1. No trackbacks yet.