CSSStyleDeclaration: phương thức removeProperty()
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.removeProperty() xóa một thuộc tính khỏi một đối tượng khai báo kiểu CSS.
Cú pháp
js
removeProperty(property)
Tham số
property-
Một chuỗi đại diện cho tên thuộc tính cần xóa. Các tên thuộc tính nhiều từ được gạch nối (kebab-case) và không phải camel-case.
Giá trị trả về
Một chuỗi bằng với giá trị của thuộc tính CSS trước khi nó bị xóa.
Ngoại lệ
NoModificationAllowedErrorDOMException-
Được ném khi thuộc tính hoặc khối khai báo là chỉ đọc.
Ví dụ
Mã JavaScript sau đây xóa thuộc tính CSS background-color khỏi một quy tắc bộ chọn:
js
const declaration = document.styleSheets[0].rules[0].style;
const oldValue = declaration.removeProperty("background-color");
Đặc tả kỹ thuật
| Specification |
|---|
| CSS Object Model (CSSOM)> # dom-cssstyledeclaration-removeproperty> |