Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
¿Cómo cambiar el estilo de un elemento recuperado de JS getelementbyid en reaccionar?

Estoy tratando de apuntar a un elemento en el DOM que ya ha sido devuelto y representado por otro componente; Esperaba usar una llamada getElementById() y luego cambiar el CSS de ese elemento.

about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

Es mala idea usar getElementById en React. Puedes usar un estilo como este

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

O asigne el atributo className a su elemento y cree estilos para esa clase en css.

 <div className="button" />
about 4 years ago · Santiago Gelvez Report

0

Puede usar element.style para cambiar las propiedades de css.

Editar: parece que no deberías usar getElementById con 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 Report

0

en el archivo css agregue #h1 { font-size: '12px'; } y en el archivo HTML use este <div id="hi"></div>

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!