Many people have used style.color, style.display, etc. to directly set the style attributes of elements, but not many people have used style.cssText.
What is the essence of cssText?
The essence of cssText is to set the style attribute value of the HTML element.
How to use cssText?
The code copy is as follows:
document.getElementById("d1").style.cssText = "color:red; font-size:13px;";
After reading this example, I believe that I don’t want to say it, but I also know what style.cssText means. It is to set the style attribute of the HTML element.
What is the return value of cssText?
In some browsers (such as Chrome), it returns whatever value you assign to it. It is more painful in IE. It will format the output, capitalize the attributes, change the order of the attributes, and remove the last semicolon, such as:
The code copy is as follows:
document.getElementById("d1").style.cssText = "color:red; font-size:13px;";
alert(document.getElementById("d1").style.cssText);
The median value in IE is: FONT-SIZE: 13px; COLOR: red.