Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
Debugging odd jQuery append()/prepend() behavior

I am trying to add elements to a <div> in the order of a score metric. Idea is to have the highest-scored sites on the top. The data that I am trying to display is in the proper order, because my SQL query forces an order. The proper order is confirmed when I do a data dump from the query into the dev console:

enter image description here

As expected, the site with score 10.39 is at the top, and the lowest is at the bottom. I then go append to my container div, but I get a weird result with .append():

enter image description here

The top ranking site is always placed on the bottom, but the other remaining sites (no matter how many I request) are always ranked and ordered properly. My code to append is as follows:

$.each(data["fetched-sites"], function(index, element){
        console.log(`Total site score: ${element["total_site_score"]}`);
        var cloned = cloneTemplate(index, element);
        console.log(`Processing site ${index}...`);
        $("#fetch-n-sites-output").append(cloned);
    });

If anyone has insight to why append is functioning like this, or what might be wrong with my code, please let me know. I then try to use prepend(), and something even more bizarre happens - the first site is repeated several times, which I cannot wrap my head around.

enter image description here

I am going through each element only once, and I cannot figure out why this behavior is occurring. Any help would be greatly appreciated. Thank you

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda