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

138
Views
El .style de mi clase es nulo en javascript

Tengo una página web simple donde en la parte superior hay un div con esto:

 <div class="divmain-login"> <div class="divmain-sup-login"> <div class="textos"> <h1>Manejo de archivos</h1> <h2>Gaspar Giménez 2021</h2><h3>v 1.2</h3> </div> </div> </div>

Quiero tener la altura del atributo de este bloque (con la clase .divmain-sup-login) con este código JS:

 function setDivSupHeight(){ const DivSup = document.querySelector(".divmain-sup-login"); console.log(DivSup.getAttribute("style")); const divh = DivSup.style.height; console.log(divh); } setDivSupHeight();

La consola devuelve esto:

nulo (línea 3)

nada (línea 7)

El estilo del atributo devuelve nulo, y este es el CSS:

 .divmain-sup-login{ position: sticky; background-color: #F56D7B; text-align: center; width: 100vw; height: 90px; display: flex; flex-flow: column wrap; justify-content: center; align-content: center; }

No sé cómo puedo obtener la altura de este bloque.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Element.getAttribute('style') y Element.style se refieren al atributo style="..." del elemento, no a nada que provenga de las reglas de estilo o el estilo calculado final, y en su caso, ese atributo no se usó de hecho, así que su valor es null .

Lo que probablemente desee aquí es Element.getComputedValue().getProperty() , consulte https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle

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