CSSStyleDeclaration.getPropertyPriority()

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.

We'd love to hear more about your role and the company you work for
Please help us by answering a few questions.

CSSStyleDeclaration.getPropertyPriority() メソッドインターフェイスは、その CSS プロパティに明示的に設定されたすべての優先度を文字列で返します。

構文

js
getPropertyPriority(property)

引数

property

文字列で、チェックするプロパティ名を表します。

返値

存在する場合は優先度("important" など)を表します。 存在しない場合は、空文字列を返します。

以下の JavaScript コードは、 margin が CSS セレクターのルールで important と記されているかどうかをチェックします。

js
const declaration = document.styleSheets[0].cssRules[0].style;
const isImportant = declaration.getPropertyPriority("margin") === "important";

仕様書

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

ブラウザーの互換性