javascript 에서 동적으로 style 적용
참조 : http://www.phpied.com/dynamic-script-and-style-elements-in-ie/
function btn1Click1() { //create style tag
var cssStr = "div {color:blue;}";
var styleSheet = document.createElement("style");
styleSheet.setAttribute("id", "id1");
styleSheet.setAttribute("type", "text/css");
if (styleSheet.styleSheet) { //IE
styleSheet.styleSheet.cssText = cssStr;
}
else { // W3
var css = document.createTextNode(cssStr);
styleSheet.appendChild(css);
}
var head = document.getElementsByTagName("head")[0];
var id1 = document.getElementById("id1");
if (!id1)
head.appendChild(styleSheet);
}
function btn1Click2() { //remove style tag
var id1 = document.getElementById("id1");
var head = document.getElementsByTagName("head")[0];
if (id1)
head.removeChild(id1);
}