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

105
Visualizações
document.body.style.backgroundColor getting executed after next line

my teacher is asking us a question and i couldn't find an answer: when pressing a button on page, run those two lines:

document.body.style.backgroundColor = "Green";
alert("Done");

why is it first alerting "Done", and then changing the background color? thanks.

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

0

This is the alert behavior. It is triggered before page loaded. To prevent this behavior, try alert the message asynchronnaly. Like this:

document.body.style.backgroundColor="green";
setTimeout(alert, 50, "Done");
about 4 years ago · Juan Pablo Isaza Relatório

0

beacuse the code is already done when u press the putton if u need to make it run before changing color u can use setTimeout(code, [delay]); delay for num of mill seconds thah u need to wait before executing

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