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

168
Visualizações
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
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