Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Re: Accessing style properties within JavaScript

Thread Tools

Re: Accessing style properties within JavaScript

Keith Bowes
Posts: n/a
      08-07-2003 Removed) 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 ( alert ("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 is an empty
string, which evaluates to false. Use:
if (typeof( == 'string')

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing Datagrid properties within a user control from the outside Craig G ASP .Net 3 11-30-2004 02:51 PM
Need help with Style conversion from Style object to Style key/value collection. Ken Varn ASP .Net Building Controls 0 04-26-2004 07:06 PM
Style sheets, include one style within another (not inheritance) HTML 1 11-24-2003 01:37 PM
Re: Accessing style properties within JavaScript Lasse Reichstein Nielsen HTML 0 08-07-2003 10:13 AM
Re: Accessing style properties within JavaScript e n | c k m a HTML 0 08-07-2003 07:23 AM