Javascript examples for DOM HTML Element:Style
Create CSS Selector rule with Javascript
<html> <head> <meta name="viewport" content="width=device-width"> </head> <body> <div class="should-be-red"> I should be red </div> <script> var styleElement = document.createElement('style'); document.head.appendChild(styleElement); var sheet = styleElement.sheet;//from w w w . j a va 2 s. co m sheet.insertRule('.should-be-red { color: red; }', 0); </script> </body> </html>