Easy Tutorial
❮ Dom Obj Month Prop Anchor Rel ❯

CSSStyleDeclaration setProperty() Method

CSS CSSStyleDeclaration

Example

Setting a new CSS property:

var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color", "yellow");

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 Chrome IE Firefox Safari Opera
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 be created or modified.
value Optional. The new property value.
priority Optional. A string indicating whether the property should be set with the priority 'important'. <br>Can be one of the following values: <br>"important" <br>undefined <br>""

Technical Details

DOM Version: CSS Object Model
Return Value: undefined
--- ---

More Examples

Example

Setting a new CSS property with "important" priority:

var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color", "yellow", "important");

CSS CSSStyleDeclaration

❮ Dom Obj Month Prop Anchor Rel ❯