wrote:
> Hi All!
>
> Is it possible to access a particular property of a style rule without
> reference to an element that uses the rule?
>
> The hack I have tried is this: create a dummy element and set its
> class to match a style rule and then access the style property.
> However, I have found that my test for this does not work (code
> below). The hard coded <p> element displays, so does the <div> created
> by the JavaScript - but I don't see an alert box telling me the
> color..
>
> Any help would be much appreciated!
>
> Rob
> 
>
> <html><head>
> <style type="text/css">
> .test{ color:#939393; }
> </style>
> <script type="text/javascript" language="JavaScript">
> function getStyle() {
> var dummy = document.createElement ("div");
> dummy.className = "test";
> var dummyText = document.createTextNode("testing testing one
> two three");
> dummy.appendChild (dummyText);
> var body = document.getElementsByTagName ("body") [0];
> body.appendChild (dummy);
> if (dummy.style.color) alert ("style color: " +
> dummy.style.color);
> } // end getStyle function
> </script>
> </head><body onLoad="getStyle();">
> <p class="test">Testing text</p>
> </body></html>
The reason that doesn't work is that dummy.style.color is an empty
string, which evaluates to false. Use:
if (typeof(dummy.style.color) == 'string')