Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Summary

CSSStyleDeclaration represents a collection of CSS property-value pairs. It is used in a few APIs:

Attributes

CSSStyleDeclaration.cssText
Textual representation of the declaration block. Setting this attribute changes the style.
CSSStyleDeclaration.length
The number of properties. See the item method below.
CSSStyleDeclaration.parentRule
The containing CssRule.

Methods

CSSStyleDeclaration.getPropertyPriority()
Returns the optional priority, "important". Example: priString= styleObj.getPropertyPriority('color')
CSSStyleDeclaration.getPropertyValue()
Returns the property value. Example: valString= styleObj.getPropertyValue('color')
CSSStyleDeclaration.item()
Returns a property name. Example: nameString= styleObj.item(0) Alternative: nameString= styleObj[0]
CSSStyleDeclaration.removeProperty()
Returns the value deleted. Example: valString= styleObj.removeProperty('color')
CSSStyleDeclaration.setProperty()
No return. Example: styleObj.setProperty('color', 'red', 'important')
CSSStyleDeclaration.getPropertyCSSValue()
Only supported via getComputedStyle. Returns an ROCSSPrimitiveValue in Firefox (CSSPrimitiveValue, in others, which implements CSSValue), or null for Shorthand properties. Example: cssString= window.getComputedStyle(elem, null).getPropertyCSSValue('color').cssText;
Note: Gecko 1.9 returns null unless using getComputedStyle().
Note: This method may be deprecated by the W3C , and it is not present in the latest CSSOM draft. It is not supported by IE and even though the function exists in Opera, calling it throws a DOMException NOT_SUPPORTED_ERR.

Example

var styleObj= document.styleSheets[0].cssRules[0].style;
alert(styleObj.cssText);
for (var i = styleObj.length-1; i >= 0; i--) {
   var nameString = styleObj[i];
   styleObj.removeProperty(nameString);
}
alert(styleObj.cssText);

Notes

The declaration block is that part of the style rule that appears within the braces and that actually provides the style definitions (for the selector, the part that comes before the braces).

See also

Specification

CSSOM: CSSStyleDeclaration

Document Tags and Contributors

 Last updated by: fscholz,