Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7012863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:18:39+00:00 2026-05-27T22:18:39+00:00

How can a sort the listitems with the sortList[0] or sortList[1] ? example: http://jsfiddle.net/wmaqb/20/

  • 0

How can a sort the listitems with the sortList[0] or sortList[1]?

example: http://jsfiddle.net/wmaqb/20/

HTML

 <div id="sortable">        
    <div id="sort_18b0c79408a72">Berlin</div>
    <div id="sort_dkj8das9sd98a">Munich</div>
    <div id="sort_skd887f987sad">Browntown</div>
    <div id="sort_54asdliöldawf">Halle</div>
    <div id="sort_f5456sdfefsdf">Hamburg</div>     
</div>

<input id="sortList0Bt" type="button" value="sortList0" />
<input id="sortList1Bt" type="button" value="sortList1" />

JS

sortList= new Array();

sortList[0] = {};
sortList[0]['18b0c79408a72'] = 6;
sortList[0]['dkj8das9sd98a'] = 9;
sortList[0]['skd887f987sad'] = 3;
sortList[0]['54asdliöldawf'] = 1;
sortList[0]['f5456sdfefsdf'] = 5;

sortList[1] = {};     
sortList[1]['18b0c79408a72'] = 1;
sortList[1]['dkj8das9sd98a'] = 2;
sortList[1]['skd887f987sad'] = 3;
sortList[1]['54asdliöldawf'] = 4;
sortList[1]['f5456sdfefsdf'] = 5;   

$("#sortable").sortable();

$('#sortList0Bt').click(function() {  sortIt(sortList[0]);   });
$('#sortList1Bt').click(function() {  sortIt(sortList[1]);   });  

JS – sort function

function sortIt(sortList)
{
   var mylist = $('#sortable');
   var listitems = mylist.children('div').get();

   listitems.sort(function(a, b)
   {
        // --------------- >>> HERE <<< --------------
   }); 

   $.each(listitems, function(idx, itm) { mylist.append(itm); });
}

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:18:41+00:00Added an answer on May 27, 2026 at 10:18 pm

    Basically you want multiple buttons that sort the same list in a different way, if I understand you correctly?

    I would suggest changing the following:

    <input id="sortList0Bt" class="sortbutton" type="button" value="sortList0" />
    <input id="sortList1Bt" class="sortbutton" type="button" value="sortList1" />
    
    $('.sortbutton').click(function() {  
        var id = parseInt($(this).val().replace("sortList","")); 
        //The above gives you "0" or "1" which is then parsed to an int
        sortIt(sortList[id]);  
    });
    

    Now you don’t have any click-handling hardcoded, only the buttons themselves.

    It does seem rather inefficient to have to manually create your sort-arrays like you do. I’m not sure how much freedom you have when using .sortable() or with the div ID’s (those ID’s themselves aren’t making it clearer either), but I would suggest doing this via classes or adding an element inside the div which your sort function can use to order them.

    E.g.:

    <div id="sort_18b0c79408a72">
        Berlin
        <input type="hidden" class="sort_me_for_button_0" id="0_1">
        <input type="hidden" class="sort_me_for_button_1" id="1_4">
    </div>
    

    If button 0 is clicked, the element will be displayed in 1st place. If button 1 is clicked, the element will be displayed in 4th place.
    Fully writing this will take some amount of brain power but I think it’s the most efficient and clear way to handle this.

    To give you an idea of how you would sort them:

    <div id="mysortedlist"></div>
    
    function sortIt(id) { //not the sortList, just the 0 or 1 int we parsed earlier.
        var number_of_items = $(".sort_me_for_button_"+id).length; //Now we know how many items there are to sort.
    
        for (int i = 1; i < number_of_items + 1; i++) {
            $("#mysortedlist").append( $("#" + id + "_" + i).parent() ); //the parent() is the div in which the hidden field resides.
        };
    
        $("#sortable").html($("#mysortedlist").html());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can SQLite sort naturally? For example, CREATE TABLE animals ( id INTEGER NOT NULL
How can you sort the following word by the given rule? Example data is
Is there a way in .NET that I can sort my collection when I
The UNIX sort command can sort a very large file like this: sort large_file
I know that JTable can sort by a single column. But is it possible
It's helpful to name threads so one can sort out which threads are doing
I'm trying to develop a function that can sort through a string that looks
Can I sort a list of objects by a property of an associated object?
How can I sort an array based on two specific values within the array?
How can I sort the dates in Perl? my @dates = ( 02/11/2009 ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.