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 2015年7月.
parentRule は CSSRule インターフェイスのプロパティで、現在のルールを内包するルールがあれば、それを返します。なければ 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> |