Style cssTextProperty

Style 对象参考手册Style Object

Definition and Usage

The cssText property sets or returns the content of a style declaration as a string.

Syntax

Set the cssText property:

Object.style.cssText="string"

Return the cssText property:

Object.style.cssText

Value Description
string Specifies the content of the style declaration.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the cssText property.


Examples

Examples

Get the style declaration as a string:

<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>

Try it Yourself »


Style 对象参考手册Style Object Other Extensions