Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

112
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda