CSSRule.cssText

  • Revision slug: DOM/CSSRule/cssText
  • Revision title: cssText
  • Revision id: 309027
  • Created:
  • Creator: Brettz9
  • Is current revision? No
  • Comment

Revision Content

{{ DomRef() }}

Summary

cssText returns the actual text of the style rule. To be able to set a stylesheet rule dynamically, see Using dynamic styling information

Syntax

string = cssRule.cssText 

Example

<style>
body { background-color: darkblue; }
</style>
<script>
  var stylesheet = document.styleSheets[0];
  alert(stylesheet.cssRules[0].cssText); // body { background-color: darkblue; }
</script>

Specification

DOM Level 2 Style - cssRule

{{ languages( {"zh-cn": "zh-cn/DOM/CSSRule/cssText" } ) }}

Revision Source

<p>{{ DomRef() }}</p>
<h3 id="Summary" name="Summary">Summary</h3>
<p><strong>cssText</strong> returns the actual text of the style rule. To be able to set a stylesheet rule dynamically, see <a href="/en-US/docs/DOM/Using_dynamic_styling_information" title="/en-US/docs/DOM/Using_dynamic_styling_information">Using dynamic styling information</a></p>
<h3 id="Syntax" name="Syntax">Syntax</h3>
<pre class="eval">
<em>string</em> = cssRule.cssText 
</pre>
<h3 id="Example" name="Example">Example</h3>
<pre class="brush:html;">
&lt;style&gt;
body { background-color: darkblue; }
&lt;/style&gt;
&lt;script&gt;
&nbsp; var stylesheet = document.styleSheets[0];
&nbsp; alert(stylesheet.cssRules[0].cssText); // body { background-color: darkblue; }
&lt;/script&gt;

</pre>
<h3 id="Specification" name="Specification">Specification</h3>
<p>DOM Level 2 Style - cssRule</p>
<p>{{ languages( {"zh-cn": "zh-cn/DOM/CSSRule/cssText" } ) }}</p>
Revert to this revision