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

How to write inline style in JS?

coldplay.xixi
coldplay.xixiOriginal
2020-06-30 15:37:075318browse

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

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

 // alert(box.style.color);
    // alert(box.style.fontSize);

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

 //alert(box.style.float);

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

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

5. Give float Assignment, and compatible with all browsers

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

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!

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

Related articles

See more