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

197
Visualizações
How to change the style of an element retrieved from JS getelementbyid in react?

I'm trying to target an element in the the DOM that has already been returned, and rendered, by another component; I was hoping to use a getElementById() call, and then change the CSS of that element.

about 4 years ago · Santiago Gelvez
3 Respostas
Responde à pergunta

0

Its bad idea to use getElementById in React. You can use style like this

<div style={{ height: 10 }}>
  Hello World!
</div>

Or give attribute className to your element and make styles for that class in css.

<div className="button" />
about 4 years ago · Santiago Gelvez Relatório

0

You can use element.style to change css properties.

Edit : It seems that you shouldn't use getElementById with React.

let element = document.getElementById('hi')
element.style.color = "white";
element.style.backgroundColor = "black";
<div id="hi">Hello</div>

about 4 years ago · Santiago Gelvez Relatório

0

in the css file add #h1 { font-size: '12px'; } and in HTML file use this <div id="hi"></div>

about 4 years ago · Santiago Gelvez 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