In javascript's style.css Text tutorial, javascriptcsstext
Many people use style. color, style. display, and other elements to directly set style attributes, but there are not many style.css Text users.
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?
Copy codeThe Code is as follows:
Document. getElementById ("d1" ).style.css Text = "color: red; font-size: 13px ;";
After reading this example, I believe that I don't know what style.css Text means. It sets the style attribute of the HTML element.
What is the returned value of cssText?
In some browsers (such as Chrome), If you assign it a value, it returns the value. In IE, it is quite painful. It will format the output, capital the attributes, change the attribute order, and remove the last Semicolon. For example:
Copy codeThe Code is as follows:
Document. getElementById ("d1" ).style.css Text = "color: red; font-size: 13px ;";
Alert (document. getElementById ("d1" ).style.css Text );
In IE, the value is: FONT-SIZE: 13px; COLOR: red.
The question of creating elements and attaching style attributes in JavaScript is as follows: code
The style attribute of an element is a read-only attribute and cannot be assigned directly. It can only be set for sub-attributes, as shown in figure
Like. style. width = "100px ";
Another solution is to set multiple attributes at the same time:
Like.style.css Text = "width: 150px; height: 150px ;"
Of course, this will overwrite the original style definition on the like element. If necessary, the security method is as follows:
Like.style.css Text + = "width: 150px; height: 150px ;"
ClassName in javascript works, but how can I change the style?
Table1.rows (3). style = "background-color: # ccffee ;";
To:
Table1.rows(32.16.style.css Text = "background-color: # ccffee ;";