Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

167
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda