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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:55:54+00:00 2026-05-20T23:55:54+00:00

the problem is I have a list with contacts and when someone change his/her

  • 0

the problem is I have a list with contacts and when someone change his/her status I try to move them to the top of the list. Everything worked till now, with IE9, and Firefox 4 is not working. I show you the code:

function sortByStatus()
{

  var divs = getElementsByClassName(document,"status_sort");
  divs.sort(compare);

  for (var i = 0; i < divs.length; i++)
  {
    $("#contact_info").append(divs[i]);
  }
}

function compare(div1, div2)
{
  var id1 = div1.getAttribute("id");
  var id2 = div2.getAttribute("id");
  if (id1 > id2)
    return 1;
  else if (id1 < id2)
    return -1;
  else
    return 0;
}

Any idea or possible fix? Thank you.

update

I have tried MrBuuBuu solution and it works patially, because now the sort by status works but the alphabetic sort is not working. I had to change part of MrBuuBuu solution, the compare function, because I compare the name of the contacts with a number just before the name that represent the status (ex. 2John , 2 means offline, and 1 online) so I have to compare with ‘<‘ and ‘>’ and return 1, -1 or 0.

But what is worst, now it doesn’t work with IE7 or IE8… the sort by status is not working.

Really weird, any idea?

  • 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-20T23:55:55+00:00Added an answer on May 20, 2026 at 11:55 pm

    document.getElementsByClassName returns a NodeList, not an array. So you have to convert it to an array first. I also cleaned up your compare() function.

    function compare(div1, div2)
    {
      var id1 = div1.id;
      var id2 = div2.id;
    
      if (id1 < id2) {
          return - 1;
      }
      if (id1 == id2) { 
          return 0;
      }
      return 1;
    }
    
    function sortByStatus()
    {
    
      var divs     = document.getElementsByClassName("status_sort");
      var divArray = $.map(divs, function(div) { return div; });
    
      divArray.sort(compare);
    
      $.each(divArray, function(i, div){
          $("#contact_info").append(div);     
      });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, here's the problem: I have a list of contacts, which i have created
Possible Duplicate: Java - Regex problem I have list of URLs of types: http://www.example.com/pk/etc
I need help with CMD scripts. Here is my problem: I have list of
The problem: I have a div where I will have a list of selections
Here is the problem: I have a list of items with various length for
Okay, so here's my problem: I have a list of members on a website,
The problem is: I have a list of objects, with some containing the same
Example of the problem If I have a list of valid option strings which
I have a problem with random and arrays. I have a list empty list
I have problem adding arraylist to list view, will explain about my problem here..

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.