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

256
Visualizações
Javascript - Best way to implement loading spinner

New to web-development and trying wrap my head around handling the DOM. Want to implement a spinner that appears while data is being processed and disappears after. I figure the order should be something like this

  1. on button press, make spinner visible and call data function
  2. after data function is finished make spinner invisible again

Using Bootstrap 5

Current implementation is something along these lines:

document.getElementById("button").addEventListener("click",function(){document.getElementById("spinner").classList.toggle("invisible");})
document.getElementById("button").addEventListener("click",dataProcess());
document.getElementById("button").addEventListener("click",function(){document.getElementById("spinner").classList.toggle("invisible");})

I understand the order in which event listeners are added are the order they are executed in but the spinner doesn't toggle at because the DOM doesn't update until all the functions are executed(since it toggled twice by then it's just invisible again). Is there a way to update the DOM between events or a better way to implement the spinner altogether?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

document.getElementById("button").addEventListener("click",()=>{
    setTimeOut(()=>{
        document.getElementById("spinner").classList.toggle("invisible")
    },600)
    dataProcess();
    document.getElementById("spinner").classList.toggle("invisible")
});
about 4 years ago · Juan Pablo Isaza Relatório

0

Give a callback function to dataprocess function and make button invisible

about 4 years ago · Juan Pablo Isaza Relatório
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