Cod-nes Posted July 14, 2010 Share Posted July 14, 2010 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 More sharing options...
Synook Posted July 14, 2010 Share Posted July 14, 2010 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 More sharing options...
dsonesuk Posted July 14, 2010 Share Posted July 14, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.