Home > Web Front-end > JS Tutorial > body text

Tutorial on using style.cssText in JavaScript_javascript skills

WBOY
Release: 2016-05-16 16:32:02
Original
1646 people have browsed it

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 HTML elements.

How to use cssText?

Copy code The code is as follows:

document.getElementById("d1").style.cssText = "color:red; font-size:13px;";

After reading this example, I believe you also know what style.cssText means. It is to set the style attribute of HTML elements.

What is the return value of cssText?

In some browsers (such as Chrome), whatever value you assign to it will be returned. In IE, it is more painful. It will format the output, capitalize attributes, change the order of attributes, and remove the last semicolon, such as:

Copy code The code is as follows:

document.getElementById("d1").style.cssText = "color:red; font-size:13px;";
alert(document.getElementById("d1").style.cssText);

The values ​​in IE are: FONT-SIZE: 13px; COLOR: red.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template