CSSStyleRule: styleMap-Eigenschaft

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Die schreibgeschützte Eigenschaft styleMap der CSSStyleRule-Schnittstelle gibt ein StylePropertyMap-Objekt zurück, das Zugriff auf die Eigenschaft-Wert-Paare der Regel bietet.

Wert

Ein StylePropertyMap-Objekt.

Beispiel

Das folgende Beispiel zeigt, wie styleMap verwendet wird, um einen Stil mit der StylePropertyMap.set()-Methode zu ändern.

js
const stylesheet = document.styleSheets[0];

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

Spezifikationen

Specification
CSS Typed OM Level 1
# dom-cssstylerule-stylemap

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
styleMap

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.