CSSStyleDeclaration: thuộc tính parentRule

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Thuộc tính chỉ đọc CSSStyleDeclaration.parentRule trả về một CSSRule là phần tử cha của khối kiểu này, ví dụ: một CSSStyleRule đại diện cho kiểu của một bộ chọn CSS.

Giá trị

Quy tắc CSS chứa khối khai báo này hoặc null nếu CSSStyleDeclaration này không được gắn với một CSSRule.

Ví dụ

Mã JavaScript sau đây lấy quy tắc kiểu CSS cha từ một CSSStyleDeclaration:

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

Đặc tả kỹ thuật

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

Tương thích trình duyệt