How TO - Sort a List❮ Previous Next ❯ Show Learn how to sort an HTML list, using JavaScript. Click the button to sort the list alphabetically: Sort
Try it Yourself » How to sort dropdown list items in jQuery?JS
How do I sort alphabetically in drop down?Creating the Drop Down List
Sort Dropdown list items using jQueryIn this post, find out jQuery code to sort dropdown list items. The items can be sorted by item's text or by item's value in ascending or descending order. Related Post:
To sort the items, use JavaScript sort method. Sort method takes sortfunction as parameter which defines the sort order. Below jQuery code sorts the dropdown list items by their text in ascending order. See result below
Above both jQuery code sorts the items in ascending order. If you want to sort them in descending order then just need to make a small change. Instead of using "<" then sign, return $(x).val() < $(y).val() ? -1 : 1;Use ">" sign for comparison and it will sort the items in descending order. See Complete Code Feel free to contact me for any help related to jQuery, I will gladly help you. Scripts Used on This Site |