CSSStyleDeclaration setProperty () Metode
Contoh
Setel properti CSS baru:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow");
Definisi dan Penggunaan
Metode setProperty() menetapkan baru atau memodifikasi properti CSS yang ada di blok deklarasi CSS.
Dukungan Peramban
Method | |||||
---|---|---|---|---|---|
setProperty() | Yes | 9.0 | Yes | Yes | Yes |
Sintaksis
object.setProperty(propertyname, value, priority)
Nilai Parameter
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 "" |
Detail Teknis
Versi DOM: | Model Objek CSS |
---|---|
Nilai Kembali: | tidak terdefinisi |
Lebih Banyak Contoh
Contoh
Tetapkan properti CSS baru dengan prioritas "penting":
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow", "important");
Contoh
Ubah properti CSS yang ada:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("color",
"blue");
Objek Deklarasi CSSStyle