In javascript's style.css Text tutorial, javascriptcsstext

Source: Internet
Author: User

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 ;";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.