CSSStyleDeclaration.getPropertyValue()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.

CSSStyleDeclaration.getPropertyValue() メソッドインターフェイスは、指定された CSS プロパティの値を含む文字列を返します。

構文

js
getPropertyValue(property)

引数

property

文字列で、チェックするプロパティ名(ハイフン区切り)を表します。

返値

プロパティの値が入った文字列です。設定されていなかった場合、空文字列を返します。

次の JavaScript コードは、 CSS セレクタールールの margin プロパティの値を問い合わせます。

js
const declaration = document.styleSheets[0].cssRules[0].style;
const value = declaration.getPropertyValue("margin"); // "1px 2px"

仕様書

Specification
CSS Object Model (CSSOM)
# dom-cssstyledeclaration-getpropertyvalue

ブラウザーの互換性

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
getPropertyValue

Legend

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

Full support
Full support