English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSSStyleDeclaration cssText 属性

 JavaScript CSSStyleDeclaration オブジェクト

cssText属性設定または返還要素のインラインスタイルの値。

文法:

返還cssText属性:

element.style.cssText

設定cssText属性:

element.style.cssText = style
<h1 id="s1" style="color:red;">CSSStyleDeclaration cssText 属性</h1>
<p id="result"></p>
<script>
function myFunc() {
   var elem = document.getElementById("s1");
   var output = document.getElementById("result");
   output.innerHTML = elem.style.cssText;   // "color: red;"
}
テストを見て‹/›

ブラウザの互換性

すべてのブラウザでcssText属性は完全にサポートされています:

属性
cssTextはいはいはいはいはい

技術的詳細

返り値:指定された要素のインラインスタイルを表す文字列
DOMバージョン:二級スタイルCSS

さらに多くの例

この例では、要素のインラインスタイル宣言のテキストを設定しています:

document.getElementById("s1").style.cssText = 'color: coral;';
テストを見て‹/›

この例では、cssText属性を使用せずに要素のテキストの色を設定しています:

document.getElementById("s1").style.color = 'coral';
テストを見て‹/›

 JavaScript CSSStyleDeclaration オブジェクト