CSSStyleDeclaration setProperty() Method

❮ CSSStyleDeclaration Object

Example

Set a new CSS property:

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

Description

The setProperty() method sets a new or modifies an existing CSS property in a CSS declaration block.


Browser Support

Method
setProperty() Yes 9.0 Yes Yes Yes

Syntax

object.setProperty(propertyname, value, priority)

Parameter Values

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
""

Technical Details

DOM Version: CSS Object Model
Return Value: undefined

More Examples

Example

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 »

Example

Modify an existing CSS property:

var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("color", "blue");
Try it Yourself »

❮ CSSStyleDeclaration Object
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.