Easy Tutorial
❮ Prop Text Type Prop Legend Form ❯

Window getComputedStyle() Method

Window Object


Definition and Usage

The getComputedStyle() method is used to retrieve the CSS styles of a specified element.

The retrieved styles are the final rendered styles of the element in the browser.

Syntax

window.getComputedStyle(element, pseudoElement)

Parameter Description:

Return Value


Browser Support

The numbers in the table indicate the first browser version that supports the method.

Method
getComputedStyle() 11.0 9.0 4.0 5 11.5

Example

Retrieve 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;
}

Window Object

❮ Prop Text Type Prop Legend Form ❯