Phương thức CSSStyleDeclaration setProperty()
❮ Đối tượng CSSStyleDeclaration
Ví dụ
Đặt thuộc tính CSS mới:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow");
Hãy tự mình thử »Sự miêu tả
Phương thức setProperty() đặt một thuộc tính CSS mới hoặc sửa đổi thuộc tính CSS hiện có trong khối khai báo CSS.
Hỗ trợ trình duyệt
Method | |||||
---|---|---|---|---|---|
setProperty() | Yes | 9.0 | Yes | Yes | Yes |
Cú pháp
object .setProperty( propertyname, value, priority )
Giá trị tham số
Parameter | Description |
---|---|
propertyname | Required. A String representing the name of the property to set |
value | Required. A String representing the new value |
priority | Optional. A String representing if the property's priority should be set to
important or not. Legal values: "important" undefined "" |
Chi tiết kỹ thuật
Phiên bản DOM: | Mô hình đối tượng CSS |
---|---|
Giá trị trả về: | không xác định |
Thêm ví dụ
Ví dụ
Đặt thuộc tính CSS mới với mức độ ưu tiên "quan trọng":
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow", "important");
Hãy tự mình thử »Ví dụ
Sửa đổi thuộc tính CSS hiện có:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("color",
"blue");
Hãy tự mình thử »❮ Đối tượng CSSStyleDeclaration