CSSStyleDeclaration setProperty () Methode
Voorbeeld
Stel een nieuwe CSS-eigenschap in:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow");
Definitie en gebruik
De methode setProperty() stelt een nieuwe CSS-eigenschap in of wijzigt deze in een CSS-declaratieblok.
Browserondersteuning
Method | |||||
---|---|---|---|---|---|
setProperty() | Yes | 9.0 | Yes | Yes | Yes |
Syntaxis
object.setProperty(propertyname, value, priority)
Parameterwaarden
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-versie: | CSS-objectmodel |
---|---|
Winstwaarde: | ongedefinieerd |
Meer voorbeelden
Voorbeeld
Stel een nieuwe CSS-eigenschap in met de prioriteit "belangrijk":
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow", "important");
Voorbeeld
Een bestaande CSS-eigenschap wijzigen:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("color",
"blue");
❮ CSSStyleDeclaration-object