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

108
Views
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 answers
Answer question

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 Report

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 Report
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!