CSSRule: 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.

parentRuleCSSRule インターフェイスのプロパティで、現在のルールを内包するルールがあれば、それを返します。なければ null を返します。

包含するルールの型の CSSRule を返します。現在のルールがメディアクエリーの中にある場合は、 CSSMediaRule になります。包含するルールがない場合は null を返します。

css
@media (min-width: 500px) {
  .box {
    width: 100px;
    height: 200px;
    background-color: red;
  }

  body {
    color: blue;
  }
}
js
let myRules = document.styleSheets[0].cssRules;
let childRules = myRules[0].cssRules;
console.log(childRules[0].parentRule); // a CSSMediaRule

仕様書

Specification
CSS Object Model (CSSOM)
# dom-cssrule-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