CSSStyleDeclaration.parentRule

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.parentRule は読み取り専用のプロパティで、このスタイルブロックの親である CSSRule を返します。例えば、 CSS セレクターのスタイルを表す CSSStyleRule です。

この宣言ブロックを含む CSS ルール、またはこの CSSStyleDeclarationCSSRule に割り当てられていない場合は null を返します。

次の JavaScript コードは、 CSSStyleDeclaration から親の CSS スタイルルールを取得します。

js
const declaration = document.styleSheets[0].rules[0].style;
const rule = declaration.parentRule;

仕様書

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

ブラウザーの互換性

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
parentRule

Legend

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

Full support
Full support