Home > Article > Web Front-end > Usage examples of cssText in js (code example)
The content this article brings to you is about the usage examples (code examples) of cssText in js. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
The essence of cssText is to set the style attribute value of HTML elements.
1. Usage
In the browser, whatever value is assigned will be returned. But in IE, it will format the output, capitalize the attributes, change the order of the attributes, and remove the last semicolon
document.getElementById("id").style.cssText = "color:red; font-size:13px;";
The result in IE: FONT-SIZE: 13px; COLOR: red
But writing this way will clear the original cssText. For example, if there is 'display:none;' in the original style, then after executing the above JS, the display will be deleted. . You can use the cssText accumulation method:
document.getElementById("id").style.cssText += "color:red; font-size:13px;";
2. The general method of setting styles
var element= document.getElementById(“id”); element.style.color=”red”; element.style.font-size=”13px”;
Related recommendations:
js Clever use of cssText attribute to batch operate styles_javascript tips
What are the methods of using the cssText method of the style object
Use facts to prove the high performance of cssText in js_javascript skills
The above is the detailed content of Usage examples of cssText in js (code example). For more information, please follow other related articles on the PHP Chinese website!