cssText
Summary
Gets or sets a textual representation of a CSS rule.
Property of css/cssom/CSSRule/CSSRulecss/cssom/CSSRule/CSSRule
Syntax
var ruleText = rule.cssText;
rule.cssText = ruleText;
Return Value
Returns an object of type StringString
Returns a textual representation of a CSS rule.
Examples
<div id="myDiv"></div>
<input type="button" value="Blue" id="blueButton">
<input type="button" value="Red" id="redButton">
<script>
    redButton.onclick=function(){
        //create a css style using cssText
        myDiv.style.cssText = "background-image: radial-gradient(red,  yellow); color: darkred;"
        // write the cssText to the contents of the div
        myDiv.innerHTML = "The cssText value is: " + myDiv.style.cssText;
    }
    blueButton.onclick=function(){
        //create a css style using cssText
        myDiv.style.cssText = "background-image: radial-gradient(blue,  white); color: darkblue;"
        // write the cssText to the contents of the div
        myDiv.innerHTML = "The cssText value is: " + myDiv.style.cssText;
    }
</script>
Related specifications
- DOM Level 2 Style
- Recommendation
See also
Related articles
CSSOM
- cssText