CSSStyleDeclaration metodo setProperty()
Esempio
Imposta una nuova proprietà CSS:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow");
Definizione e utilizzo
Il metodo setProperty() imposta una nuova proprietà CSS o modifica una esistente in un blocco di dichiarazione CSS.
Supporto browser
Method | |||||
---|---|---|---|---|---|
setProperty() | Yes | 9.0 | Yes | Yes | Yes |
Sintassi
object.setProperty(propertyname, value, priority)
Valori dei parametri
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 "" |
Dettagli tecnici
Versione DOM: | Modello a oggetti CSS |
---|---|
Valore di ritorno: | non definito |
Altri esempi
Esempio
Imposta una nuova proprietà CSS con priorità "importante":
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow", "important");
Esempio
Modifica una proprietà CSS esistente:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("color",
"blue");
❮ Oggetto CSSStyleDeclaration