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

133
Visualizações
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 Respostas
Responde à pergunta

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