Javascript examples for DOM HTML Element:Style
Call insertRule() function on style element sheet property
<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 ww w . j a va2s.c o m*/ sheet.insertRule('.should-be-red { color: red; }', 0); </script> </body> </html>