Home > Web Front-end > JS Tutorial > Usage examples of cssText in js (code example)

Usage examples of cssText in js (code example)

不言
Release: 2018-08-11 11:17:01
Original
2618 people have browsed it

The content this article brings to you is about the usage examples (code examples) of cssText in js. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

The essence of cssText is to set the style attribute value of HTML elements.

1. Usage

In the browser, whatever value is assigned will be returned. But in IE, it will format the output, capitalize the attributes, change the order of the attributes, and remove the last semicolon

document.getElementById("id").style.cssText = "color:red; font-size:13px;";
Copy after login

The result in IE: FONT-SIZE: 13px; COLOR: red

But writing this way will clear the original cssText. For example, if there is 'display:none;' in the original style, then after executing the above JS, the display will be deleted. . You can use the cssText accumulation method:

document.getElementById("id").style.cssText += "color:red; font-size:13px;";
Copy after login

2. The general method of setting styles

var element= document.getElementById(“id”);
element.style.color=”red”;
element.style.font-size=”13px”;
Copy after login

Related recommendations:

js Clever use of cssText attribute to batch operate styles_javascript tips

What are the methods of using the cssText method of the style object

Use facts to prove the high performance of cssText in js_javascript skills

The above is the detailed content of Usage examples of cssText in js (code example). For more information, please follow other related articles on the PHP Chinese website!

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