CSSStyleDeclaration: parentRule property

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

{{ APIRef("CSSOM") }}

The CSSStyleDeclaration.parentRule read-only property returns a {{domxref('CSSRule')}} that is the parent of this style block, e.g., a {{domxref('CSSStyleRule')}} representing the style for a CSS selector.

Value

The CSS rule that contains this declaration block or null if this {{domxref('CSSStyleDeclaration')}} is not attached to a {{domxref('CSSRule')}}.

Examples

The following JavaScript code gets the parent CSS style rule from a {{domxref('CSSStyleDeclaration')}}:

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

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}