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

173
Views
appending element before executing time consuming function doesnt work; element gets inserted when function finished

I have a function doing some calculations that takes about 2-3 seconds. While that fuction runs, I want to display a loader onto the page, until the function finishes. However, the loader gets inserted to the page not until the function finished. The function inserts a canvas that shows the results once it finished, maybe thats causing a problem? Because when I replace that function with a setTimeout, I dont have any problems. I also replaced it with a function that logs "HI" 10000 times, but I get the same effect as with setTimeout; the loader displays correctly. Used code:

var header = document.querySelector(".header");

var loader = document.createElement("div");
loader.className = "loader";

header.append(loader);
 
var master = new CalculatingMaster();
master.calculateAndDisplayResults();
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!