English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript CSS Style Declaration Object

-

1
var output = document.getElementById("result");
function myFunc1() {
   var styleObj = heading.style;
   output.innerHTML = styleObj.cssText;
}
function myFunc2() {
   var prop = window.getComputedStyle(heading, null).getPropertyValue("color");
   output.innerHTML = prop;
}
Test and see‹/›

HTMLElement.styleHandle the inline styles of a single element.

window.getComputedStyle()Expose the CSSStyleDeclaration object as a read-only interface.

CSSStyleDeclaration Object Properties

The following table lists the properties of the CSSStyleDeclaration object:

PropertyDescription
cssTextSet or return the text representation of the CSS declaration block
lengthReturn the number of style declarations in the CSS declaration block
parentRuleReturn the CSS rule that is the parent of the style block

CSSStyleDeclaration Object Methods

The following table lists the methods of the CSSStyleDeclaration object:

MethodDescription
getPropertyPriority()Return whether the specified CSS property has an 'important' rule set
getPropertyValue()Return the value of the specified CSS property
item()Return CSS property names from the CSS declaration block by index
removeProperty()Remove CSS properties from the CSS declaration block
setProperty()Set new or modify existing CSS properties in the CSS declaration block