Javascript dynamically changes the CSS style

Source: Internet
Author: User
In web page display, sometimes some CSS attributes need to be dynamically changed. You can only change individual attributes in CSS, such as character sets, or change the full set of CSS attributes. There are already many similar themes. CodeInstance. Here is a brief summary.

1. The style attribute of an object can be used only to change individual attributes, such as style. fontfamily.
Note that only the first character after the "-" line in CSS needs to be capitalized: font-family fontfamily. vs2008 is alreadyProgramPersonnel should be prepared. Specifically, the floaters are style.stylefloatits other style.css float.

2. If there are multiple schemes in the same CSS file and the scheme is class, you can modify the class attribute of the DOM object, such:
VaR olddiv = Document. getelementsbyid (divid );
Olddiv. classname = "newclassname ";

3. To change the CSS file, you need to change the href attribute under the link tag.
For example, <link href = "songti.css" id = "divcss" rel = "stylesheet" type = "text/CSS"/> change its href.
......
VaR newcss = Document. getelementsbyid (divcss );
Newcss. href = "new.css ";
......

Related Article

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.