Home > DeveloperSection > Forums > How to sort multiselected items?
Tom Cruser
Tom Cruser

Total Post:28

Posted on    October-31-2014 12:51 AM

 JQuery JavaScript 

 1 Reply(s)
 948  View(s)
Rate this:
I have already finished the function of grouping the selected items and unselected items, but I need to sort them in alphabetic order meanwhile. My js code is shown below:


        beforeopen: function (event, ui) {

            var selected = $("#id option:selected");






How can I achieve this?

Barbara Jones

Total Post:13

Posted on    October-31-2014 12:54 AM

Here's a nice(-ish) way to do it:

$("#clickity").click(function () {

        $("#derp>span").sort(function (a, b) {

            return (a.textContent || a.innerText).localeCompare(b.textContent || b.innerText);



<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<div id="derp"><span>g</span><span>o</span><span>t</span><span>h</span><span>s</span></div>

<button id="clickity">Sort!</button>

Don't want to miss updates? Please click the below button!

Follow MindStick