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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:41:18+00:00 2026-05-11T18:41:18+00:00

I have the following structure: <div id=container> <div id=someid1 style=float:right></div> <div id=someid2 style=float:right></div> <div

  • 0

I have the following structure:

<div id="container">
<div id="someid1" style="float:right"></div>
<div id="someid2" style="float:right"></div>
<div id="someid3" style="float:right"></div>
<div id="someid4" style="float:right"></div>
</div>

Now someid is acually a unique id for that div. Now i receive an array which has a different order say someid 3,2,1,4, then how do i move these divs around to match the new order using jQuery?

Thankyou very much for your time.

  • 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-11T18:41:18+00:00Added an answer on May 11, 2026 at 6:41 pm

    My plugin version – Working Demo

    Takes an array and optional id prefix and reorders elements whose ids correspond to the order of (id prefix) + values inside the array. Any values in the array that don’t have an element with the corresponding id will be ignored, and any child elements that do not have an id within the array will be removed.

    (function($) {
    
    $.fn.reOrder = function(array, prefix) {
      return this.each(function() {
        prefix = prefix || "";
    
        if (array) {    
          for(var i=0; i < array.length; i++) 
            array[i] = $('#' + prefix + array[i]);
    
          $(this).empty();  
    
          for(var i=0; i < array.length; i++)
            $(this).append(array[i]);      
        }
      });    
    }
    })(jQuery);
    

    Code from the demo

    jQuery

     $(function() {
      $('#go').click(function() {
    
        var order = $('#order').val() == ""? null: $('#order').val().split(",");
        $('#container').reOrder(order, 'someid');
      });
    });
    
    (function($) {
    
    $.fn.reOrder = function(array, prefix) {
      return this.each(function() {
        prefix = prefix || "";
    
        if (array) {    
          for(var i=0; i < array.length; i++) 
            array[i] = $('#' + prefix + array[i]);
    
          $(this).empty();  
    
          for(var i=0; i < array.length; i++)
            $(this).append(array[i]);      
        }
      });    
    }
    })(jQuery);
    

    HTML

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <title>reOrder Demo</title>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <style type="text/css" media="screen">
    body { background-color: #fff; font: 16px Helvetica, Arial; color: #000; }
    div.style { width: 200px; height: 100px; border: 1px solid #000000; margin: 5px; }
    </style>
    </head>
    <body>
    <div id="container">
    <div id="someid1" class="style" style="background-color:green;">div1</div>
    <div id="someid2" class="style" style="background-color:blue;">div2</div>
    <div id="someid3" class="style" style="background-color:red;">div3</div>
    <div id="someid4" class="style" style="background-color:purple;">div4</div>
    </div>
    <p>Pass in a comma separated list of numbers 1-4 to reorder divs</p>
    <input id="order" type="text" />
    <input id="go" type="button" value="Re-Order" />
    
    
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I have a relatively simple design that is puzzling me. It has 4 large
I have the following ASPX structure: <UpdatePanel id=OutsidePanel UpdateMode=Conditional> <div runat=server id=myDiv> <UpdatePanel id=InsidePanel
I am trying to create a dynamic menu by reading an XML file using
I have the following HTML node structure: <div id=foo> <div id=bar></div> <div id=baz> <div

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.