Window getComputedStyle() Method
Definition and Usage
The getComputedStyle() method is used to get the CSS styles of a specified element.
The retrieved styles are the styles of the element as finally rendered in the browser.
Syntax
window.getComputedStyle(element, pseudoElement)
Parameter Description:
- element: Required. The element whose style is to be retrieved.
- pseudoElement: Optional. A pseudo-element; can be omitted or passed as null when no pseudo-element is queried.
Return Value
The returned object is of type CSSStyleDeclaration.
Browser support
The numbers in the table indicate the first browser version that supports this method.
| Method | |||||
|---|---|---|---|---|---|
| getComputedStyle() | 11.0 | 9.0 | 4.0 | 5 | 11.5 |
Example
Example
Get the background color value of a DIV:
function
myFunction
(
)
{
var
elem
=
document
.
getElementById
(
"
test
"
)
;
var
theCSSprop
=
window
.
getComputedStyle
(
elem
,
null
)
.
getPropertyValue
(
"
background-color
"
)
;
document
.
getElementById
(
"
demo
"
)
.
innerHTML
=
theCSSprop
;
}
Try it »
Window Object