JS Modify CSS Style

Source: Internet
Author: User

Modify Width:

document.getElementById ("Div1"). Style.width= "200px";

Modify Border-radius:

document.getElementById ("Div1"). style.borderradius= "100px";

To modify a background image:

document.getElementById ("Div1"). Style.backgroundimage= ' url (img.jpg) ';


document.getElementById ("Div1"). style.csstext= "border-radius:100px; width:200px; Background-image:url (img.jpg) ";


1: Use style. Property name = "attribute Value" when the property name may have to be changed, such as Border-radius to become borderradius;background-image to become backgroundimage;

But when using Style.csstext, the name of the property is written in the same way as the CSS.

2: The two methods are best not to mix, when the Style.csstext set, written in the code before the Style.width and so will be invalidated.

CSS Reference manual: http://www.ziqiangxuetang.com/cssref/css-reference.html


JS Modify CSS Style

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.