CSSStyleDeclaration setProperty () Methode
Beispiel
Legen Sie eine neue CSS-Eigenschaft fest:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow");
Definition und Verwendung
Die Methode setProperty() legt eine neue CSS-Eigenschaft fest oder ändert eine vorhandene CSS-Eigenschaft in einem CSS-Deklarationsblock.
Browser-Unterstützung
Method | |||||
---|---|---|---|---|---|
setProperty() | Yes | 9.0 | Yes | Yes | Yes |
Syntax
object.setProperty(propertyname, value, priority)
Parameterwerte
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 "" |
Technische Details
DOM-Version: | CSS-Objektmodell |
---|---|
Rückgabewert: | nicht definiert |
Mehr Beispiele
Beispiel
Legen Sie eine neue CSS-Eigenschaft mit der Priorität „wichtig“ fest:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow", "important");
Beispiel
Ändern Sie eine vorhandene CSS-Eigenschaft:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("color",
"blue");
❮ CSSStyleDeclaration-Objekt