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

245
Visualizações
NextJS is not stylizing div after adding new class

I am coding this front-end with NextJS framework and after the user clicks the target button, a class will be added to a specific div. This class is supposed to change the div style, once I had added unique styles to this class in my css file.

The original element:

<div class="Home_wordBlockWrapper__nwyZO" id="generated-block"><h3>C</h3></div>

The element after clicking the button:

<div class="Home_wordBlockWrapper__nwyZO filled rightindex" id="generated-block"><h3>C</h3></div>

CSS File:

.wordBlockWrapper {
  border: 2px solid rgb(226, 232, 240); 
  border-radius: 5px;
  width: 50px;
  height: 50px;
}

.wordBlockWrapper {
  justify-content: center;
  align-items: center;
  text-align: center;
  display: flex;
  transition: .5 ease-in-out;
}

.filled {
  border: 2px solid black;
}

The problem is: Though the class is added, the div style remains the same. Do you guys know where is the error?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Well, I doesn't solved my question with an usual way. But, anyway, my solution was: Instead of trying to add a class to the element and then after stylizing it in the css file, I added a JS script to add the styles in the document element, getting it by its id.

Solution:

var tb = document.getElementsByClassName(styles.wordBlockWrapper)[matching.index]
var targBlockId = document.getElementById(tb.id);
  
if(targBlockId !== null) {
    targBlockId.style.backgroundColor = "#13d178"
    targBlockId.style.color = "#fff"
}

This way, the issue is solved adding the styles with a JS script, instead of adding a class to its classList and then stylizing it with css files.

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