CSSStyleDeclaration setProperty () Método
Ejemplo
Establezca una nueva propiedad CSS:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow");
Definición y uso
El método setProperty() establece una propiedad CSS nueva o modifica una existente en un bloque de declaración CSS.
Compatibilidad con navegador
Method | |||||
---|---|---|---|---|---|
setProperty() | Yes | 9.0 | Yes | Yes | Yes |
Sintaxis
object.setProperty(propertyname, value, priority)
Valores paramétricos
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 "" |
Detalles técnicos
Versión DOM: | Modelo de objetos CSS |
---|---|
Valor de retorno: | indefinido |
Más ejemplos
Ejemplo
Establezca una nueva propiedad CSS con prioridad "importante":
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow", "important");
Ejemplo
Modificar una propiedad CSS existente:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("color",
"blue");
❮ Objeto CSSStyleDeclaration