Método CSSStyleDeclaration setProperty ()
Exemplo
Defina uma nova propriedade CSS:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow");
Definição e uso
O método setProperty() define uma nova ou modifica uma propriedade CSS existente em um bloco de declaração CSS.
Suporte ao navegador
Method | |||||
---|---|---|---|---|---|
setProperty() | Yes | 9.0 | Yes | Yes | Yes |
Sintaxe
object.setProperty(propertyname, value, priority)
Valores de parâmetro
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 "" |
Detalhes técnicos
Versão DOM: | Modelo de objeto CSS |
---|---|
Valor de retorno: | Indefinido |
Mais exemplos
Exemplo
Defina uma nova propriedade CSS com prioridade "importante":
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow", "important");
Exemplo
Modifique uma propriedade CSS existente:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("color",
"blue");
❮ Objeto CSSStyleDeclaration