CSSStyleDeclaration setProperty() Method
Example
Set a new CSS property:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color", "yellow");
Try it yourself »
Definition and Usage
The setProperty() method is used to set a new CSS property, and can also modify existing properties in the CSS declaration block.
Browser Support
| Method | |||||
|---|---|---|---|---|---|
| setProperty() | Yes | 9.0 | Yes | Yes | Yes |
Syntax
object.setProperty(propertyname, value, priority)
Property Values
| Parameter | Description |
|---|---|
| propertyname | Required. A string representing the property to create or modify. |
| value | Optional. The new property value. |
| priority | Optional. A string specifying whether the property priority needs to be set to important. Can be one of the following three values: "important" undefined "" |
Technical Details
| DOM Version: | CSS Object Model |
|---|---|
| Return Value: | undefined |
More Examples
Example
Set a new CSS property with the "important" priority:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color", "yellow", "important");
Try it yourself »
CSS CSSStyleDeclaration