CSSStyleDeclaration setProperty () Metoda
Przykład
Ustaw nową właściwość CSS:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow");
Definicja i użycie
Metoda setProperty() ustawia nową lub modyfikuje istniejącą właściwość CSS w bloku deklaracji CSS.
Obsługa przeglądarki
Method | |||||
---|---|---|---|---|---|
setProperty() | Yes | 9.0 | Yes | Yes | Yes |
Składnia
object.setProperty(propertyname, value, priority)
Wartości parametrów
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 "" |
Szczegóły techniczne
Wersja DOM: | Model obiektowy CSS |
---|---|
Wartość zwrotu: | nieokreślony |
Więcej przykładów
Przykład
Ustaw nową właściwość CSS z priorytetem „ważne”:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow", "important");
Przykład
Zmodyfikuj istniejącą właściwość CSS:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("color",
"blue");
❮ Obiekt CSSStyleDeclaration