Sets or retrieves the persisted representation of the style rule.
Syntax
| JavaScript | |
|---|
Property values
Type: String
the text.
Remarks
This property reflects the current state of the rule and not its initial value.
Examples
This example uses the cssText property to retrieve the CSS style set on an object.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/cssText.htm
<P ID=oPara STYLE="color:'green'; font-weight:bold"> This is the test paragraph.</P> : <BUTTON onclick="alert(oPara.style.cssText)"> Get CSS attributes</BUTTON>
Send comments about this topic to Microsoft
Build date: 3/14/2012
The number of rules that can be applied at one time with cssText is 4095.
Be careful to invoke the property on the styleSheet object itself, not the HTMLElement returned by getElementById or createElement. For newly created stylesheet objects, you must first append the element to the document before you can set cssText.
var ss = document.createElement('STYLE');
document.documentElement.firstChild.appendChild(ss);
ss.styleSheet.cssText = " ... style rules go here ... ";