CSSStyleDeclaration setProperty () Metoda
Příklad
Nastavte novou vlastnost CSS:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow");
Definice a použití
Metoda setProperty() nastavuje novou nebo upravuje existující vlastnost CSS v bloku deklarace CSS.
Podpora prohlížeče
Method | |||||
---|---|---|---|---|---|
setProperty() | Yes | 9.0 | Yes | Yes | Yes |
Syntax
object.setProperty(propertyname, value, priority)
Hodnoty parametrů
Parameter | Description |
---|---|
propertyname | Required. A String representing the name of the property to set |
value | Optional. A String representing the new value |
priority | Optianal. A String representing if the property's priority should be set to
important or not. Legal values: "important" undefined "" |
Technické údaje
Verze DOM: | Objektový model CSS |
---|---|
Návratová hodnota: | nedefinováno |
Další příklady
Příklad
Nastavte novou vlastnost CSS s "důležitou" prioritou:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow", "important");
Příklad
Upravte existující vlastnost CSS:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("color",
"blue");
❮ Objekt CSSStyleDeclaration