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

134
Views
The .style of my class is null in javascript

I have a simple web page where on the top there´s a div with this:

<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>

I want to have the attribute height of this block (with the class .divmain-sup-login) with this JS code:

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

    const divh = DivSup.style.height;
    console.log(divh);
}

    setDivSupHeight();

The console returns this:

null (line 3)

nothing (line 7)

The atrribute style returns null, and this is the 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;
}

I dont know how can i get the height of this block.

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

0

Element.getAttribute('style') and Element.style refer to the style="..." attribute of the element - not to anything coming from style rules or final computed style, and in your case that attribute was not used indeed so it's value is null.

What you actually probably want here is Element.getComputedValue().getProperty(), see 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!