English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
JavaScript CSSStyleDeclaration Object
cssTextSet or return the value of the inline style of the element.
Return cssText property:
element.style.cssText
Set cssText property:
element.style.cssText = style
<h1 id="s1" style="color:red;">CSSStyleDeclaration cssText property</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;" }Test and see‹/›
All browsers fully support the cssText property:
Property | |||||
cssText | Yes | Yes | Yes | Yes | Yes |
Return Value: | A string representing the inline style of the specified element |
---|---|
DOM Version: | Secondary Style CSS |
This example sets the text of the inline style declaration of the element:
document.getElementById("s1").style.cssText = 'color: coral;';Test and see‹/›
This example sets the color of the element text without using the cssText property:
document.getElementById("s1").style.color = 'coral';Test and see‹/›