Availability
DOM Level 2 CSS
Synopsis
CSSStyleDeclaration getComputedStyle(Element elt,String pseudoElt);
Arguments
elt
The document element whose style information is desired. pseudoElt
The CSS pseudoelement, or null if there is none.
Returns
A read-only CSSStyleDeclaration object (which typically also
implements the CSS2Properties interface) that specifies the style
information used to render the specified element in this view. Any
length values queried from this object are always absolute or pixel
values, not relative or percentage values.
Description
An element
in a document may obtain style information from an inline
style attribute and from any number of style
sheets in the style-sheet "cascade." Before the element
can actually be displayed in a view, its style must be
"computed" by extracting style information from the
appropriate parts of the cascade.
This method allows access to those computed styles. By contrast, the
style property of an element gives you access only
to the inline styles of an element and tells you nothing about
style-sheet attributes that apply to the element. Note that this
method also provides a way to determine the actual pixel coordinates
at which an element is rendered in this view.
getComputedStyle( ) is actually defined by the
ViewCSS interface. In any DOM implementation that supports the View
and CSS modules, any object that implements AbstractView always
implements ViewCSS also. So, for simplicity, this method has been
listed with AbstractView.
In Internet Explorer, similar functionality is available through the
nonstandard currentStyle property of each
HTMLElement object.
See Also
CSS2Properties, CSSStyleDeclaration, HTMLElement.style