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