Home  >  Article  >  Web Front-end  >  Tutorial on using style.cssText in JavaScript_javascript skills

Tutorial on using style.cssText in JavaScript_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:32:021618browse

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.

Statement:
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