Home  >  Article  >  Web Front-end  >  Compatible writing method of addRule under firefox_javascript skills

Compatible writing method of addRule under firefox_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:23:401176browse

There are really many ways to use scripts to control the style of html elements.
For a single element, you can directly use element.style.display=... to modify one style, or you can use element.className=... to modify its multiple styles.
To modify the styles of multiple elements, you can use scripts to directly import css files.
There is such a requirement in the current project. It is required to change the style of all descendant nodes under a certain div, but not change the style of the div itself.
I left the code without thinking:

Copy the code The code is as follows:






divdiv

spanspan

ttttt





<script> <br>function f(){ <br> var rule="#a1 *{background-color:red}"; <br> var index=document.styleSheets[0].cssRules.length; <br> document.styleSheets[0].insertRule(rule, index); <br>} <br></script>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn