René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
Dynamically creating Style Sheets with JavaScript | ||
See insertRule
It seems like IE uses addRule instead of insertRule.
<html> <head><title>Dynamically creating style sheets with JavaScript</title> <script language='javascript'> var css = document.createStyleSheet('dyn css', 'projection,tv,screen'); if (css.insertRule) { css.insertRule ('p.blue {color:blue;}'); css.insertRule ('p.red {color:red; }'); } else if (css.addRule) { css.addRule('p.red' , 'color:red;' ); css.addRule('p.blue', 'color:blue;'); } </script> </head> <body> <p class='blue'>This text should be blue <p class='red'> This text should be red </body> </head> |