Set a new CSS property:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color", "yellow");
Try it Yourself »
The setProperty() method sets a new or modifies an existing CSS property in a CSS declaration block.
Method | |||||
---|---|---|---|---|---|
setProperty() | Yes | 9.0 | Yes | Yes | Yes |
object.setProperty(
propertyname, value, priority)
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 "" |
DOM Version: | CSS Object Model |
---|---|
Return Value: | undefined |
Set a new CSS property with "important" priotrity:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color", "yellow", "important");
Try it Yourself »
Modify an existing CSS property:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("color", "blue");
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!