Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Window getComputedStyle() Method

Window getComputedStyle() Method

Window Object Reference Window Object


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:

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 Reference Window Object