Csstext Setting CSS Styles

Source: Internet
Author: User

Use Csstext to set CSS styles in JS(2012-08-21 10:40:22)reproduced
Tags: js
If the page has an ID of "no" tag, for the time being Div tag to tell;
To set the CSS style of 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.
In general it will be combined with CSS to add classname or change the classname to achieve the desired effect, but if you create an element, do you want to be so simple? It's going to be 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"});
Of course there are simpler, csstext:var obj = document.getelementbyidx_x_x (' no ');
Obj.style.cssText = "width:400px; height:300px; "; Of course, this method is very simple and convenient for the element initialization CSS style of Create.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.