If you add a CSS style to an element in a Web page that id= "mydiv", get the node first:
var obj = document.getElementById ("mydiv");
To add CSS to a node:
If you need to add a few CSS, you can obj.style.width = "300px";
If you need to add more than one CSS statement, this will be more than one, such as:
Obj.style.width= "300px";
Obj.style.height= "300px";
Obj.style.border= "1px solid #ddd";
......
This will be a bit of a hassle, and you need to repeatedly write similar statements, then you can:
(1) Set CSS by writing JS function yourself
function Setcss (OBJ,CSS) {
for (var attr in CSS) {
OBJ.STYLE[ATTR] = css[attr];
}
}
Setcss (obj,{"width": "300px", "height": "300px", "Border": "1px solid #ddd"}});
(2) Setting CSS through the Csstext method
Obj.style.cssText = "width:300px;height:300px;border:1px solid #ddd;";
This will be simple and convenient, especially for the new Create element to initialize the CSS style
JS set multiple CSS Styles