Home > Web Front-end > JS Tutorial > How to write inline style in JS?

How to write inline style in JS?

coldplay.xixi
Release: 2020-06-30 15:37:07
Original
5369 people have browsed it

The way to write the inline style is: 1. To write the compound attribute, remove the "—" in the middle and capitalize the second word. The code is [alert(box.style.color)]; 2. float is a keyword with a special way of writing, the code is [alert(box.style.float)].

How to write inline style in JS?

The writing method of inline style in JS is:

1. Access element style 1, the stye attribute is only for inline The style is useful

var box = document.getElementById("box");
Copy after login

2. To write compound attributes, remove the "—" in the middle and capitalize the second word.

 // alert(box.style.color);
    // alert(box.style.fontSize);
Copy after login

3. Float is a keyword, so it is best not to write like this

 //alert(box.style.float);
Copy after login

4. There are differences between float attributes ie and non-ie:

 // alert(box.style.cssFloat); //非ie
    // alert(box.style.styleFloat); //IE专用
Copy after login

5. Give float Assignment, and compatible with all browsers

 // typeof box.style.cssFloat !="undefined"?box.style.cssFloat = "right":box.style.styleFloat ="right";
Copy after login

Related learning recommendations:javascript video tutorial

The above is the detailed content of How to write inline style in JS?. 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