Home > Article > Web Front-end > How to write inline style in JS?
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)].
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!