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

150
Visualizações
Trying to find a way to control background color via 11 different buttons. Question about template strings?

I have 11 buttons with their own class, as well as all 11 share the class .theme-color. I am trying to have it change to the background color on the button class. My idea was to get the class into the function and add a . to the beginning, then use the style.background to it to get the value in css.

let allThemes = document.querySelectorAll('.theme-color');
allThemes.forEach(theme => theme.addEventListener('click', themeState()));
function themeState() {
  return function (event) {
    let classFilter = event.target.classList[1];
    console.log(classFilter);
    let helpDocument = document.querySelector(`.${classFilter}`);
    console.log(helpDocument);
  };
}

Something tells me I can't do this but honestly I cannot figure out any other way. Each class has a (class).style.background = undefined even though it has it set in CSS.

Help please.

about 4 years ago · Juan Pablo Isaza
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