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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:19:03+00:00 2026-05-22T16:19:03+00:00

If I have several divs: <div data-sort=’1′>div1</div> <div data-sort=’4′>div4</div> <div data-sort=’8′>div8</div> <div data-sort=’12’>div12</div> <div

  • 0

If I have several divs:

<div data-sort='1'>div1</div>
<div data-sort='4'>div4</div>
<div data-sort='8'>div8</div>
<div data-sort='12'>div12</div>
<div data-sort='19'>div19</div>

And I dynamically create the divs:

<div data-sort='14'>div1</div>
<div data-sort='6'>div1</div>
<div data-sort='9'>div1</div>

How can I get them to just sort into the divs already loaded in order, without having to reload all of the divs?

I think that I would need to build an array of the data-sort values of all of the divs on the screen, and then see where the new divs fit in, but I am not sure if this is the best way.

  • 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-22T16:19:04+00:00Added an answer on May 22, 2026 at 4:19 pm

    Use this function

       var result = $('div').sort(function (a, b) {
    
          var contentA =parseInt( $(a).data('sort'));
          var contentB =parseInt( $(b).data('sort'));
          return (contentA < contentB) ? -1 : (contentA > contentB) ? 1 : 0;
       });
    
       $('#mylist').html(result);
    

    You can call this function just after adding new divs.

    If you want to preserve javascript events within the divs, DO NOT USE html replace as in the above example. Instead use:

    $(targetSelector).sort(function (a, b) {
        // ...
    }).appendTo($container);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several divs that I want to work with dynamically. <div class=parent-19 id=123>
I have a DIV container with several inner DIVs layed out by floating them
I have a container DIV which contains several block-DIVS. Every block-DIV contains SPAN items
I have several divs on a page. They are formatted like: <div id='profile-1'></div> <div
I have several divs with one class on a page. <div class=main/> <div class=main/>
I have several divs like this: <div class=MenuList><a class=SiteLink href=page.aspx>My Link</a></div> The problem is
So I have a div that can have several divs inside of it. Something
I have several vertically stacks divs and I want to have a div appear
I have a webpage with a div which contains several other divs WITHOUT an
If you have several div s on a page, you can use CSS to

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.