If you want to dynamically modify the css global style in the page, for example, change the color of all fonts on the page to red
This can be achieved through css
*{color:red;}
And if you use js to modify the styles of all elements on the page, that is, click the button through js to dynamically modify the styles of all elements on the page to red, how should you implement it
I can only think of this method.
Use css style-related interfaces
stylesheet.insertRule
或者stylesheet.addRule
Both of these can dynamically insert css styles. The compatibility is good with ie9+For example
When you need to delete, there are
deleteRule
和removeRule
two methods. You can check the relevant information[].forEach.call(document.querySelectorAll('*'),function(a){
a.style.color = 'red';
})