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

220
Visualizações
How do I create an active class with css and javascript for my5 star rating react component?

I would like to be able to have a rating component that consist of five stars like this where the active class is added to the span element when clicked and all the span elements before it. (like a. 5 star rating would just have to be clicked once on the 5th span) The active class would need to be removed from any spans after it when clicked as well. How can I achieve this?

<span>*</span>
<span>*</span>
<span>*</span>
<span>*</span>
<span>*</span>
</div>

// React is loaded and is available as React and ReactDOM (I'm not using imports)

  render() {
    return null;
  }
}

document.body.innerHTML = "<div id='root'> </div>";
  
const rootElement = document.getElementById("root");
ReactDOM.render(<Rating />, rootElement);

document.querySelectorAll("span")[2].click();
console.log(document.getElementById("rating").outerHTML);
about 4 years ago · Santiago Gelvez
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