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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:09:25+00:00 2026-06-11T23:09:25+00:00

I’m working on a jQuery code which sorts all the divs with class order_me

  • 0

I’m working on a jQuery code which sorts all the divs with class “order_me” in a page according to such a criterion.

These divs are arranged in container rows made by divs, i.e.:

<div id="container">
    <div class="row">
      <div  class="order_me"></div>
      <div  class="order_me"></div>
      <div  class="order_me"></div>
    </div> 
    <div class="row">
       <div  class="order_me"></div>
       <div  class="order_me"></div>
       <div  class="order_me"></div>
    </div>
    <div class="row">
       <div  class="order_me"></div>
    </div>
</div> 

Once that I get the list of divs to be ordered, i.e.

var $lst = $('#container').find('.order_me')); 

and then I convert the list as JS Array and I sort it like follows:

var array = jQuery.makeArray($lst);
array.sort(sortingFunction);

Since I have the list of already sorted divs: how can I efficiently put the sorted divs in the rows?

Of course, if you have something else in mind show me your idea.

Note that the last row could have less divs, while the others have the same number of divs.

Thanks in advance.
Regards. JV

  • 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-06-11T23:09:27+00:00Added an answer on June 11, 2026 at 11:09 pm

    Let me give a shot:

    var $rows = $('.row');
    var limit = $($rows[0]).find('.order_me').length;
    var $lst = $('#container').find('.order_me'));
    var array = jQuery.makeArray($lst);
    array.sort(sortingFunction);
    
    var count = 0;
    var rowIndex = 0;
    for(var i in array){
        var div = array[i];
        $($rows[rowIndex]).append($(div));
        count++;
        if(count >= limit){
            count = 0;
            rowIndex++;
        }
    }
    

    basicly I captured the number of divs in the first row to use as limit
    I loop through the array, append the div to the row based on rowIndex and add to the counter.
    when counter reaches limit we start to append divs to the next row by increasing rowIndex, until all elements are appended to the right place.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.