Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda