JS Modify CSS File

Source: Internet
Author: User
Tags change settings

In doing self-change settings, inadvertently saw the JS modify CSS method, feel very useful, special to learn to share. Okay, here's the beginning: JS's document.stylesheets gets an array of objects that are introduced into the CSS. Such as:

Where Cssstylesheet expands as follows:

document.stylesheets[0] It is different to get the first cssrules and cssrules that you apply! Rules are the first few selectors; Cssrules is the rule document.stylesheets[0].cssrules to get all the CSS file lines document.stylesheets[  0].cssrules[0] CSS first document.stylesheets[0].cssrules[0]. style.background="Red"// Modify the background color of the first bar to be red

Instance:

Change the font color of Heading 1 to the CSS introduced in red:
. wode{    Color: #000;    font-size:36px;}. article{    color: #333;} h1,h2,h3{    color: #0D9BF2;}
<! DOCTYPE html>

 

Before modification:

After modification:

 

JS Modify CSS File

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.