<html>
<head>
<title>Dynamic Style Example 2</title>
</head>
<body>
<p>You should see the background color change after clicking the button.</p>
<input type="button" value="Add Style" onclick="addStyle()">
<script type="text/javascript">
function loadStyleString(css){
var style = document.createElement("style");
style.type = "text/css";
try{
style.appendChild(document.createTextNode(css));
} catch (ex){
style.styleSheet.cssText = css;
}
var head = document.getElementsByTagName("head")[0];
head.appendChild(style);
}
function addStyle(){
loadStyleString("body{background-color:red}");
}
</script>
</body>
</html>