0

I think I already missed you haha :)

It's very strange that when i do the function Sort them by Alphabetically content, it's duplicate the div... How I can reach the goal, without duplicating?

(I also would like to order, by date. It's like, each person, will have a date. And in this list, I can show the people by date)

As you can see in the code, I split each object (human) in 1 div. In this case when we move by Nickname, it will also move his lastname. If not, it will do "Angelina Di Caprio" mixing names... haha..

  function OrderFunctionNickName() {
 
  $('.nickName').sort(function(a, b) {
    if (a.textContent < b.textContent) {
      return -1;
    } else {
      return 1;
    }
  }).appendTo('.slot');
}
         <p class=Click onclick="OrderFunctionNickName()">CLICK test</div>
         
         <div class=slot id=data-1>
            <p class=nickName>Mizo</p>
            <p class=firstName>Leonardo</p>
            <p class=lastName>Di Caprio</p>

            <p class=date-messages >31/07/21 [18:15]</p>
         </div>

         <div class=slot id=data-2>
            <p class=nickName>Liou</p>
            <p class=firstName>Angelina</p>
            <p class=lastName>Jolie</p>

            <p class=date-messages>27/07/21 [21:03]</p>
         </div>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Lasticote
  • 1
  • 1
  • You don't want to sort `nickName` elements. You want to sort `slot` elements (*by* nickname). – Bergi Aug 05 '21 at 20:55
  • [`appendTo`](https://api.jquery.com/appendTo/) does clone the element(s) if you try to append them to multiple targets. – Bergi Aug 05 '21 at 20:55
  • ok thank you. How i could do? – Lasticote Aug 05 '21 at 21:17
  • https://stackoverflow.com/questions/8446615/sorting-divs-by-number-inside-div-tag-and-jquery or https://stackoverflow.com/questions/1134976/how-may-i-sort-a-list-alphabetically-using-jquery should give you some idea – Bergi Aug 05 '21 at 21:26
  • i tried especially this, and that's why i posted this code :/ because it was creating problems – Lasticote Aug 07 '21 at 15:00

0 Answers0