var styles = {
"#textContainer": {
"border": "blue solid 2px;",
"background-color": "#ff0;"
},
"#textContainer > button": {
"color": "#f00"
}
};
var newStyle = document.createElement('style');
newStyle.type = "text/css";
newStyle.appendChild(document.createTextNode(getCSS()));
document.querySelector("#textContainer").appendChild(newStyle);
function getCSS() {
var css = [];
for (let selector in styles) {
let style = selector + " {";
for (let prop in styles[selector]) {
style += prop + ":" + styles[selector][prop];
}
style += "}";
css.push(style);
}
return css.join("
");
}