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
changing the background of a page with a variable

So far, I have been able to make a variable that will store the hexcode, but I can't figure out how to use that variable in order to change the background color to that color. This is my code so far:

document.body.style.backgroundColor = 'rgb(${redhex}, ${greenhex}, ${bluehex})';

where redhex, greenhex, and bluehex are all variables that the user can change for the RGB. I think that part of the issue might be that I have another variable in my code named rgb?

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

0

You might need to use a template string to interpolate other values inside the string. So in your case, it might be

document.body.style.backgroundColor = `rgb(${redhex}, ${greenhex}, ${bluehex})`;
about 4 years ago · Juan Pablo Isaza Report

0

I believe that you could also use this website https://www.rgbtohex.net/

It is a tool I use some times to convert RGB into simple hex values this will replace

rgb(${redhex}, ${greenhex}, ${bluehex}) with ${rgbHexCode}

Resulting in document.body.style.backgroundColor = ${rgbHexCode};

about 4 years ago · Juan Pablo Isaza Report

0

If I understand you, the variable is hexcode, but then, rgb doesn't take hex values. Rgb takes base 10 values from 0 to 255. Be sure to check if you are sending the right type of value

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!