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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:17:54+00:00 2026-06-11T03:17:54+00:00

I have a three-column layout, and each column has multiple divs that hold blocks

  • 0

I have a three-column layout, and each column has multiple divs that hold blocks of similar content:

<section class="info-blocks-container clearfix">
<div id="col1">
    <div class="info-block">...</div>
    <div class="info-block">...</div>
    <div class="info-block">...</div>
</div>
<div id="col2">
    <div class="info-block">...</div>
    <div class="info-block">...</div>
</div>
<div id="col3">
    <div class="info-block">...</div>
    <div class="info-block">...</div>
    <div class="info-block">...</div>
</div>
</section>

I’d like to shuffle the children divs within div#col1, div#col2, and div#col3 amongst the columns randomly, so some of #col1‘s child divs end up in #col2 and/or #col3, and vice-versa. I’m using thecodeparadox’s function reorder() found here (I removed the ‘undo’ function) and the shuffling is working, but
1. the way I have 3 separate duplicate functions is very dirty, and
2. it’s only sorting the divs within each column (it’s not sharing the children divs among the three columns):

<script type="text/javascript">
$(function(){
    reorder();
    reorder2();
    reorder3();

    function reorder() {
        var grp = $(".info-blocks-container > div:nth-child(1)").children();
        var cnt = grp.length;

        var temp, x;
        for (var i = 0; i < cnt; i++) {
            temp = grp[i];
            x = Math.floor(Math.random() * cnt);
            grp[i] = grp[x];
            grp[x] = temp;
        }
        $(grp).remove();
        $(".info-blocks-container > div:nth-child(1)").append($(grp));
    }
    function reorder2() {
        var grp = $(".info-blocks-container > div:nth-child(2)").children();
        var cnt = grp.length;

        var temp, x;
        for (var i = 0; i < cnt; i++) {
            temp = grp[i];
            x = Math.floor(Math.random() * cnt);
            grp[i] = grp[x];
            grp[x] = temp;
        }
        $(grp).remove();
        $(".info-blocks-container > div:nth-child(2)").append($(grp));
    }
    function reorder3() {
        var grp = $(".info-blocks-container > div:nth-child(3)").children();
        var cnt = grp.length;

        var temp, x;
        for (var i = 0; i < cnt; i++) {
            temp = grp[i];
            x = Math.floor(Math.random() * cnt);
            grp[i] = grp[x];
            grp[x] = temp;
        }
        $(grp).remove();
        $(".info-blocks-container > div:nth-child(3)").append($(grp));
    }
});
</script>

Any suggestions?

  • 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-11T03:17:56+00:00Added an answer on June 11, 2026 at 3:17 am

    At second, your problem was a really a challenge for me. But I think I found a solution:

    var columnsCollection = new Array();
    var columnsObjectsNumber = new Array();
    
    reorder();
    function reorder() {
        $(".info-blocks-container").find("DIV[id^='col']").each(function()
        {           
            var tmp = $(this).children();
            //Store the numbers of contained children
            columnsObjectsNumber.push($(tmp).size());
            $(tmp).each(function()
            {
                //transfers current child object to our global store place
                columnsCollection.push($(this));
                //and removed it
                $(this).remove();
            });
        });
    
        var restartIndex = 0;
        $(".info-blocks-container").find("DIV[id^='col']").each(function()
        {
            //Contains the random generated number
            var x;
            //Contains the current object with Id 'col..'
            var temp = $(this);
            for (var i = 0; i < columnsObjectsNumber[restartIndex]; i++)
            {
                /*
                  Generates a random number.
                 The maximum limit is the current length from our global store place
                */
                x = Math.floor(Math.random() * columnsCollection.length);
                //Appends the object to the current object with Id 'col..'
                $(temp).append(columnsCollection[x]);
                //Removes the appended element from global store place
                columnsCollection.splice(x,1);
             }
            restartIndex++;
        });   
    }
    

    It doesn’t looks professional, but it works. Hopefully it is what you requested for…

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

Sidebar

Related Questions

I have a layout that contains a TableLayout with three rows. Each row has
a have three column layout and i want to have three divs inside the
I have a table column where each row has one of three states, and
I have a dialog in qt that has multiple groupboxes, each using a form
I want a two-column div layout, where each one can have variable width e.g.
I have an Eclipse RCP application with a sort of three column layout: The
I have a website with a two column layout, like there are dozens I
I have three column in my datagridview .One is text ,one is Combo and
I have three buttons in a three column structure in a custom cell in
I have a three column workbook with the following data: Col A: Names Col

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.