CSSStyleRule: styleMap property

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

{{APIRef("CSSOM")}}

The **styleMap** read-only property of the {{domxref("CSSStyleRule")}} interface returns a {{domxref('StylePropertyMap')}} object which provides access to the rule's property-value pairs.

Value

A {{domxref('StylePropertyMap')}} object.

Example

The following example shows styleMap being used to modify a style using the {{domxref('StylePropertyMap.set()')}} method.

js
const stylesheet = document.styleSheets[0];

Object.values(stylesheet.cssRules).forEach((block) => {
  if (block.selectorText === "button") {
    block.styleMap.set("--main-color", "black");
  }
});

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}