If you have a label with "No" in your Web page, let's tell it as a DIV tag;
To set the CSS style for this div in JS, it is common practice to:
var obj = document.getelementbyidx_x_x (' no ');
Obj.style.width = ' 400px ';
Obj.style.height = ' 300px ';
If you want to set up a bunch of CSS styles, it's too much trouble to
Under normal circumstances will be combined with CSS to add classname or change classname to achieve the desired effect, but if you create an element, do you want to be so simple? Then we'll think of another way.
So everyone wrote one function after another, the classic two are:
var obj = document.getelementbyidx_x_x (' no ');
function SetStyle (obj, CSS) {for
(var attr in obj) {
obj.style[attr] = css[attr];
}
SetStyle (obj,{width: "400px", Height: "300px"});
There are, of course, simpler, csstext:
var obj = document.getelementbyidx_x_x (' no ');
Obj.style.cssText = "width:400px; height:300px; ";
Of course, this method is simple and convenient for initializing CSS styles for the elements of Create.
The above is small series for everyone to bring the JS with Csstext set CSS style of the whole content of the simple method, hope to help everyone, a lot of support cloud Habitat Community ~