Style cssTextプロパティ
Style オブジェクト
定義と使い方
cssText プロパティは、スタイル宣言の内容を文字列として設定または返します。
構文
cssText プロパティの設定:
Object.style.cssText="string"
cssText プロパティを返す:
Object.style.cssText
| 值 | 説明 |
|---|---|
| string | スタイル宣言の内容を指定します。 |
ブラウザサポート
![]()
![]()
![]()
![]()
![]()
すべての主要ブラウザが cssText プロパティをサポートしています。
例
例
スタイル宣言を文字列として取得:
<html>
<head>
<script>
function displayResult()
{
alert(document.getElementById("p1").style.cssText);
}
</script>
</head>
<body>
<p id="p1" style="border:2px dashed green;color:red;">This is a paragraph.</p>
<br>
<button type="button" onclick="displayResult()">Get style declaration</button>
</body>
</html>
<head>
<script>
function displayResult()
{
alert(document.getElementById("p1").style.cssText);
}
</script>
</head>
<body>
<p id="p1" style="border:2px dashed green;color:red;">This is a paragraph.</p>
<br>
<button type="button" onclick="displayResult()">Get style declaration</button>
</body>
</html>
試してみる »
Style オブジェクト その他の拡張