How to sort multiselected items?

Total Post:28


 1523  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?

  1. Re: How to sort multiselected items?

    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=""></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>

      Modified On Apr-06-2018 02:05:42 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.