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 6005481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:24:11+00:00 2026-05-23T01:24:11+00:00

can we sort the jquery sortable at runtime using the id or idx as

  • 0

can we sort the jquery sortable at runtime using the id or idx as taken by me in each li. I want it to sort in the run time

here is fiddle . I want it to auto sort for eg <li id=1> should come first than <li id=2> and so on.. Help will be appreciated as I am Novice trying to learn jquery.

Here’s the HTML:

<div class="demo" style="width:444px">

<ul id="sortable">
   <li itemID=3 id='3' class="ui-state-default">3<button>delete</button></li>
    <li itemID=6 id='6' class="ui-state-default">6<button>delete</button></li>

    <li itemID=1 id='1' class="ui-state-default">1<button>delete</button></li>
    <li itemID=4 id='4' class="ui-state-default">4<button>delete</button></li>
    <li itemID=9 id='9' class="ui-state-default">9<button>delete</button></li>
    <li itemID=2 id='2' class="ui-state-default">2<button>delete</button></li>
    <li itemID=8 id='8' class="ui-state-default">8<button>delete</button></li>
    <li itemID=5 id='5' class="ui-state-default">5<button>delete</button></li>
    <li itemID=11 id='11' class="ui-state-default">11<button>delete</button></li>
    <li itemID=7 id='7' class="ui-state-default">7<button>delete</button></li>
    <li itemID=10 id='10' class="ui-state-default">10<button>delete</button></li>

    <li  itemID=12 id='12' class="ui-state-default">12<button>delete</button></li>

</ul>

</div><!-- End demo -->

Here’s the JS:

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

    $(":button").click(function(){
    $(this).parent().remove();
    var arr=$("#sortable").sortable('toArray');
    text=arr.toString();
    alert(text);
    });

});

And here’s the CSS:

#sortable { list-style-type: none; margin: 0; padding: 0; }
#sortable li { margin: 3px 3px 3px 0; padding: 1px; float: left; width: 100px; height: 90px; font-size: 4em; text-align: center; }

I also pull in a bunch of libraries and CSS (not sure if it is required on JSFiddle or not):

<link rel="stylesheet" href="http://jqueryui.com/themes/base/jquery.ui.all.css">
<script src="http://jqueryui.com/jquery-1.5.1.js"></script>
<script src="http://jqueryui.com/ui/jquery.ui.core.js"></script>
<script src="http://jqueryui.com/ui/jquery.ui.widget.js"></script>

<script src="http://jqueryui.com/ui/jquery.ui.mouse.js"></script>
<script src="http://jqueryui.com/ui/jquery.ui.sortable.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/demos/demos.css">
  • 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-23T01:24:12+00:00Added an answer on May 23, 2026 at 1:24 am

    Check this out

    http://jsfiddle.net/wmaqb/2/

    Using the standard jQuery library and the .sort() method you can specify a function to use for sorting your array of objects.

    $('#sort').click(function() {
        var mylist = $('#sortable');
        var listitems = mylist.children('li').get();
        listitems.sort(function(a, b) {
            var compA = parseFloat($(a).attr('id'));
            var compB = parseFloat($(b).attr('id'));
            return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
        });        
        $.each(listitems, function(idx, itm) {
            mylist.append(itm);
        });
    });
    

    Once you got this array sorted, you can simply order them with a .each() cycle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the jquery sortable functionality to sort a list of items in my
I am using jQuery UI sortable to sort a list in the DOM. I
How can I sort gridview with JQuery using C#? Any share?
I've successfully implemented the jQuery sortable() plugin but want to enhance it with a
I have the following ListView in which I am using the JQuery UI sortable
I'm making a sort elements web game using jQuery, HTML & CSS. While everything
I'd like some help with the following jQuery code if possible... $(document).ready(function() { $('table.sortable').each(function()
I want to use Jquery UI Sortable to implement drag-drop and sortable display. In
How can I sort an array as the one shown below with jquery's own
I'm building a jQuery sortable list where the user can add items from a

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.