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

153
Views
create a div using javascript with its background colored randomly

1-Create an input for the person to type something and when pressing a button Create a Counter

2- A div with a colored background (randomly generate this color so that all counters are not the same)

3- The entire div must be clickable to increment the counter value

-- part 1 and 3 completed, part 2 incomplete

I would like to know if it is possible to create the divs with different colors, I implemented a random color code but it only changes the first div created and leaves the rest blank

as I couldn't post a part of the code on the site I'm leaving a link that shows the complete structure of the code

https://jsfiddle.net/8wz276rj/

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

if you're only looking for code that generates random color then

const setBg = () => {
  const randomColor = Math.floor(Math.random()*16777215).toString(16);
  document.body.style.backgroundColor = "#" + randomColor;
}

you can later set the div color through this.

about 4 years ago · Santiago Gelvez 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!