HTMLElement: attributeStyleMap プロパティ

Limited availability

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

attributeStyleMapHTMLElement インターフェイスの読み取り専用のプロパティで、生きた StylePropertyMap を返します。これには、要素のインライン スタイル属性で定義されているか、スクリプト経由で HTMLElement インターフェイスの style プロパティを使用して割り当てられた、要素のスタイルプロパティのリストが入ります。

一括指定プロパティは展開されます。border-top: 1px solid black を設定すると、代わりに個別指定プロパティ (border-top-color, border-top-style, border-top-width) が設定されます。

style プロパティと attributeStyleMap プロパティの主な違いは、style プロパティが CSSStyleDeclaration オブジェクトを返すのに対し、attributeStyleMap プロパティは StylePropertyMap オブジェクトを返すことです。

このプロパティ自身は書き込みできませんが、style プロパティを通じて返す CSSStyleDeclaration オブジェクトと同様に、このプロパティが返す StylePropertyMap オブジェクトを通じてインラインスタイルを読み書きすることができます。

生きた StylePropertyMap オブジェクトです。

次のコードは style 属性と attributeStyleMap プロパティの関係を示しています。

html
<div style="white-space: pre-line;">
  <div id="el" style="border-top: 1px solid blue; color: red;">要素の例</div>
  <div id="output"></div>
</div>
css
#el {
  font-size: 16px;
}
js
const element = document.getElementById("el");
const output = document.getElementById("output");

for (const property of element.attributeStyleMap) {
  output.textContent += `${property[0]} = ${property[1][0].toString()}\n`;
}

仕様書

Specification
CSS Typed OM Level 1
# dom-elementcssinlinestyle-attributestylemap

ブラウザーの互換性

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
attributeStyleMap

Legend

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

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

関連情報