CSSStyleDeclaration: phương thức getPropertyPriority()

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.

Phương thức giao diện CSSStyleDeclaration.getPropertyPriority() trả về một chuỗi cung cấp tất cả các độ ưu tiên được thiết lập rõ ràng trên thuộc tính CSS.

Cú pháp

js
getPropertyPriority(property)

Tham số

property

Một chuỗi đại diện cho tên thuộc tính cần kiểm tra.

Giá trị trả về

Một chuỗi đại diện cho độ ưu tiên (ví dụ: "important") nếu tồn tại. Nếu không tồn tại, trả về chuỗi rỗng.

Ví dụ

Mã JavaScript sau đây kiểm tra xem margin có được đánh dấu là important trong một quy tắc bộ chọn CSS hay không:

js
const declaration = document.styleSheets[0].cssRules[0].style;
const isImportant = declaration.getPropertyPriority("margin") === "important";

Đặc tả kỹ thuật

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

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