cascade-import-dynamic-001.xht (1041B)
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>Dynamic sheet append (<style>)</title> 5 <link rel="author" title="Boris Zbarsky" href="mailto:bzbarsky@mit.edu"/> 6 <link rel="reviewer" title="Ian Hickson" href="mailto:ian@hixie.ch"/> 7 <link rel="help" href="http://www.w3.org/TR/CSS21/selector.html" /> 8 <link rel="match" href="../reference/ref-this-text-should-be-green.xht"/> 9 <script type="text/javascript"> 10 var style = document.createElement("style"); 11 var text = document.createTextNode("body { color: red; }"); 12 style.appendChild(text); 13 document.getElementsByTagName("head")[0].appendChild(style); 14 // note: when this runs, we've only parsed as far as the next line, 15 // so the style element below doesn't exist, so we "append" 16 // before that element. 17 </script> 18 <style type="text/css"> 19 body { color: green; } 20 </style> 21 </head> 22 <body> 23 <p>This text should be green.</p> 24 </body> 25 </html>