CSSStyleDeclaration setProperty ()メソッド
例
新しいCSSプロパティを設定します。
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow");
定義と使用法
setProperty()メソッドは、CSS宣言ブロック内の新しいCSSプロパティを設定するか、既存のCSSプロパティを変更します。
ブラウザのサポート
Method | |||||
---|---|---|---|---|---|
setProperty() | Yes | 9.0 | Yes | Yes | Yes |
構文
object.setProperty(propertyname, value, priority)
パラメータ値
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 "" |
技術的な詳細
DOMバージョン: | CSSオブジェクトモデル |
---|---|
戻り値: | 未定義 |
その他の例
例
「重要な」優先度で新しいCSSプロパティを設定します。
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow", "important");
例
既存のCSSプロパティを変更します。
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("color",
"blue");
❮CSSStyleDeclarationオブジェクト