Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!