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

117
Views
¿Cómo hacer que el cuadro div cambie de color aleatoriamente cada 1000 milisegundos con HTML Javascript?

He estado tratando de descubrir cómo hacer que el cuadro div cambie de color al azar cada 1000 milisegundos. Este es mi intento de la función changeColor archivo JavaScript:

 myInterval = setInterval(changeColor, 1000); var box = document.getElementById("box"); function changeColor() { var randomColor = Math.floor(Math.random() * 16777215).toString(16); box.style.backgroundColor = "#" + randomColor; //let x = document.getElementById('contents'); //x.style.backgroundColor = x.style.backgroundColor == "yellow" ? "pink" : "yellow"; }
 <div id="box">This is some text in a div element.</div>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

como de esta manera

 var div = document.querySelector(".test"); setInterval(() => { div.style.background = `#${getColor()}`; }, 1000) function getColor() { return Math.floor(Math.random()*16777215).toString(16); }
about 4 years ago · Juan Pablo Isaza Report

0

He adjuntado la función javascript para cambiar el color de forma aleatoria cada 1000 milisegundos.

 <!DOCTYPE html> <html> <head> <title>Change bg color every 1 seconds</title> </head> <body> <div id="box">This is some text in a div element.</div> <script> setInterval( function () { var randomColor = Math.floor(Math.random()*16777215).toString(16); document.getElementById("box").style.backgroundColor = "#"+randomColor; },1000); </script> </body> </html>

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!