CSSStyleDeclaration
概要
CSSStyleDeclaration
表示了一個 CSS 屬性名值對(property-value pairs)的集合。它被用於幾個 API 當中:
HTMLElement.style
(en-US) - to manipulate the style of a single element (<elem style="...">);- (TODO: reword) is an interface to the declaration block returned by the
style
property of acssRule
in a stylesheet, when the rule is a CSSStyleRule. CSSStyleDeclaration
is also a read-only interface to the result of window.getComputedStyle().
屬性
CSSStyleDeclaration.cssText
(en-US)-
Textual representation of the declaration block. Setting this attribute changes the style.
CSSStyleDeclaration.length
(en-US) Read only-
The number of properties. See the
item()
(en-US) method below. CSSStyleDeclaration.parentRule
(en-US) Read only-
The containing
CSSRule
(en-US).
方法
CSSStyleDeclaration.getPropertyPriority()
(en-US)-
Returns the optional priority, "important".
CSSStyleDeclaration.getPropertyValue()
(en-US)-
Returns the property value given a property name.
CSSStyleDeclaration.item()
(en-US)-
Returns a property name.
CSSStyleDeclaration.removeProperty()
(en-US)-
Removes a property from the CSS declaration block.
CSSStyleDeclaration.setProperty()
(en-US)-
Modifies an existing CSS property or creates a new CSS property in the declaration block/.
CSSStyleDeclaration.getPropertyCSSValue()
(en-US) 已棄用-
Only supported via getComputedStyle in Firefox. Returns the property value as a
CSSPrimitiveValue
(en-US) ornull
for shorthand properties.
範例
var styleObj = document.styleSheets[0].cssRules[0].style;
console.log(styleObj.cssText);
for (var i = styleObj.length; i--;) {
var nameString = styleObj[i];
styleObj.removeProperty(nameString);
}
console.log(styleObj.cssText);
備註
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).
參見
規範
Specification |
---|
CSS Object Model (CSSOM) # the-cssstyledeclaration-interface |