Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

147
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda