Web Hosting Offers
See the new scripts recently added to Dynamic Drive. Click here.
Original, practical CSS codes and examples such as CSS menus for your site.
    Search code samples  
 
  Keyword
 
 
 
   
 
 
  Code Samples
 
ASP
CSS
Dhtml
Html
Javascript
PHP
 
   
     LOGIN HERE  
 
Username
Password
Forgot Password
Verify Signup
 
 
 

Javascript >> General

How do I access the current style of an element?

Visitor Ratings (0) :

Description
HTML page elements in IE4+ and NN6 have a style object property with sub properties for all the css style attributes the browser supports

e.g.
elementRef.style.color for the text color
elementRef.style.fontSize for the font size.

This style object is however not giving you the computed/cascaded style of an element but is (initially) only a reflection of the inline style set on an element and later only reflecting what you assign to it.

ie
<P STYLE="color: orange;" ONCLICK="alert(this.style.color)" >
shows you the string orange while <P ONCLICK="alert(this.style.color)">
shows you an empty string as the inline style color value is empty.

So how do you get the current computed/cascaded style of an element, in particular for elements which don't have an inline style? IE5 has
support for that with introducing the currentStyle object property for HTML page elements. Contrary to the style
object the currentStyle gives you a value for all elements, whether they have an inline style, a style class, a named style rule or no
style setting at all inheriting its styles from the document body.

Try the following with IE5 and you will see the difference between the currentStyle and the style object:
Code
Select All
 Rate this Resource