[Javascript] detecting CSS capability

Paul Novitski paul at novitskisoftware.com
Mon May 17 11:49:43 CDT 2004


At 07:15 AM 5/17/2004, Flavio Gomes wrote:
><style> someTag.someClass {background-color: navy;} </style>
><someTag id="my_id"> Hi Hi, I'm someTag passing by!! </someTag>
><script> alert(getElementById('my_id').style.backgroundColor) </script>


Flavio,

Not quite.  The DOM style property maps to the HTML style attribute, not to 
the stylesheet:

Test:
         div {color: red;}
         <div></div>
Result:
         obj.style.color == ""
         obj.currentStyle.color == "red" (IE5+)

Test:
         div {color: red;}
         <div style="color: blue;"></div>
Result:
         obj.style.color == "blue"
         obj.currentStyle.color == "blue" (IE5+)

To determine whether an IE5+ browser recognizes the stylesheet, I can 
probably test for the existence of (obj.currentStyle) in the DOM and not 
even bother to test for its value...  But of course that sounds like an 
oxymoron: is there an IE5+ browser without CSS capability?  Sure, I'll 
include currentStyle in the test just to be completist, but the focus of my 
testing will really be older agents anyway.

Cheers,
Paul 





More information about the Javascript mailing list