Jump to content

How can I check the display style?


Cod-nes

Recommended Posts

I tried several times already and it still won't work. :)

<div id="con2" style="display:block;">Text</text><script type="text/javascript">if(document.getElementById('con2').style.display == "block") { alert("Ok");}</script>

EDIT: It works now. :); Apparently, external css doesn't work.

Link to comment
Share on other sites

Why does the closing tag read "text" and not "div"? Besides being invalid, that would cause the division element to remain open past the script tag, and thus not be ready when the script is run.

Link to comment
Share on other sites

to read styling from external css, you need to use

<script type="text/javascript">if(getStyle(document.getElementById('con2'), 'display') == "block") {alert("Ok");}function getStyle(el, cssprop){ if (el.currentStyle) //IE  return el.currentStyle[cssprop] else if (document.defaultView && document.defaultView.getComputedStyle) //Firefox  return document.defaultView.getComputedStyle(el, "")[cssprop] else //try and get inline style  return el.style[cssprop]}</script>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...