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

146
Visualizações
Can't console.log() .style.display information

I'm able to correct switch between a dropdown menu being displayed and hidden when I click on my input tag, but when console logging the style displayed I get nothing shown on the console. What is the explanation for not being able to see this and how would I go about trying to correctly see which display style I used?

document.getElementById('search').addEventListener("click", function () {
    const grid1 = document.querySelector(".modal");
    grid1.style.display = grid1.style.display ? "none" : "flex";
    console.log(grid1.style.display);
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Instead of using 'yourelement.style.display' use 'getComputedStyle' function to get the value of any property in this case 'display', thats because Computed style contains all the CSS properties set to an element. Even if do not set a property to an element. You will still find that property in the computed styles.

Modifiying your code with 'getComputerStyle'

document.getElementById('search').addEventListener("click", function () {
    const grid1=document.querySelector(".modal")

    console.log(window.getComputedStyle(grid1).display)
    grid1.style.display = window.getComputedStyle(grid1).display == "none" ? "flex" : "none";
    console.log(window.getComputedStyle(grid1).display)
 })
.modal {
  display: none;
}
<input id="search">
<select class="modal"></select>

For more clarification check Window.getComputedStyle() in MDN Web Docs

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