Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Does display:none have different meaning in html and in css?

Consider the following html.

<div id="test" style="display:none"></div>
<script> console.log(document.getElementById("test").style.display) </script>

This results in none in the console log. However, if instead:

<style> #test{ display: none; } </style>
<div id="test"></div>
<script> console.log(document.getElementById("test").style.display) </script>

then it fails to determine the display property. Why is that the case?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Accessing the style of an element in javascript via element.style only works, when the style is set inline.

Otherwise, if the style is set in a css file or with the <style></style> tag, you have to use the getComputedStyle() method.

You can find further information here and in this SO question!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading