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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:12:56+00:00 2026-06-01T10:12:56+00:00

I have several divs like this <div rel=5> Divs content goes here </div> <div

  • 0

I have several divs like this

<div rel="5">
  Divs content goes here
</div>
<div rel="3">
   Div 3 Here
</div>
<div rel="4">
  Div 4 Here
 </div>
 <div rel="4.5">
   Div 4.5 here
</div>

How would you use Jquery to sort the divs so that physically in the DOM they are sorted with the least rel attribute first?

e.g.
3, 4, 4.5, 5

  • 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-01T10:12:57+00:00Added an answer on June 1, 2026 at 10:12 am

    See my fiddle: http://jsfiddle.net/6hpNz/8/

    You can leverage a combination of javascript and jQuery to do this pretty easily:

    Given the following HTML:

    <div class="unsorted">
        <div rel="5">
          Div 5 here
        </div>
        <div rel="3">
           Div 3 Here
        </div>
         <div rel="4.5">
           Div 4.5 here
        </div>
        <div rel="4">
          Div 4 Here
         </div> </div>
    <div class="sorted"></div>
    

    This script will give you the desired output:

    $(document).ready(function () {
        var sortedDivs = $(".unsorted").find("div").toArray().sort(sorter);
        $.each(sortedDivs, function (index, value) {
            $(".sorted").append(value);
        });
    });
    
    function sorter(a, b) {
        return a.getAttribute('rel') - b.getAttribute('rel');
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several DIVs with z-indexes (like: z-index: 999991;). In Safari, this results that
I have a div with several other divs inside it. I would like to
I have several divs like this: <div class=MenuList><a class=SiteLink href=page.aspx>My Link</a></div> The problem is
I have several DIVs on my page that I would like to be able
I have a wrapper containing several divs. I would like this wrapper to be
I have some HTML that looks like this: <div class=MyClass></div> <div class=MyClass></div> <div class=MyClass></div>
I have several divs on a page. They are formatted like: <div id='profile-1'></div> <div
I have a div with a table inside and several content divs in cells.
Say I have several inline-block div tags, like this <div class=image> </div> <div class=image>
I have several divs that I want to work with dynamically. <div class=parent-19 id=123>

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.