CSSStyleDeclaration setProperty() Method
Definition and Usage
setProperty()
The method sets a new CSS property in a CSS declaration block or modifies an existing property.
Example
Example 1
Set a new CSS property:
var declaration = document.styleSheets[0].cssRules[0].style; var setprop = declaration.setProperty("background-color", "yellow");
Example 2
Set a new CSS property with "important" priority:
var declaration = document.styleSheets[0].cssRules[0].style; var setprop = declaration.setProperty("background-color", "yellow", "important");
Example 3
Modify existing CSS properties:
var declaration = document.styleSheets[0].cssRules[0].style; var setprop = declaration.setProperty("color", "blue");
Syntax
object.setProperty(propertyname, value, priority)
Parameter
Parameter | Description |
---|---|
propertyname | Required. A string representing the name of the property to be set. |
value | Optional. A string representing the new value. |
priority |
Optional. A string indicating whether the priority of the attribute should be set to important. Valid Values:
|
Technical Details
DOM Version: | CSS Object Model |
---|---|
Return Value: | undefined |
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | 9.0 | Support | Support | Support |