CSSStyleRule.styleMap

Limited availability

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

styleMapCSSStyleRule インターフェイスの読み取り専用プロパティで、このルールのプロパティ/値の組にアクセスするための StylePropertyMap オブジェクトを返します。

StylePropertyMap オブジェクトです。

以下の例では、 styleMap を使用して StylePropertyMap.set() メソッドを使用し、スタイルを変更する方法を示しています。

js
const stylesheet = document.styleSheets[0];

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

仕様書

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

ブラウザーの互換性

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.