Tutorial Inject New CSS Rules
If you need to change the style of an element with JavaScript, it's typically better to change a class name and have the CSS already on ...
https://iskablogs.blogspot.com/2014/03/tutorial-inject-new-css-rules.html
If you need to change the style of an element with JavaScript, it's typically better to change a class name and have the CSS already on the page take effect and change the style. However, there are exceptions to every rule. For instance, you might want to programmatically change the a pseudo class (e.g. :hover). You can't do that through JavaScript for the same reason inline style="" attributes