xxxxxxxxxx
var cssjson = {
".copy-1":{
"font-family":"Verdana, Geneva, Arial, Helvetica, sans-serif",
"font-size":"11px",
"color":"#CCC"
},
"div#container div#header":{
"CSSJSON-INHERIT-SELECTOR":".copy-1",
"position":"absolute",
"top":"12px",
"left":"4px"
}
}
var styleStr = "";
for(var i in cssjson){
styleStr += i + " {\n"
for(var j in cssjson[i]){
if(j=="CSSJSON-INHERIT-SELECTOR"){
for(var k in cssjson[cssjson[i][j]]){
styleStr += "\t" + k + ":" + cssjson[cssjson[i][j]][k] + ";\n"
}
}else{
styleStr += "\t" + j + ":" + cssjson[i][j] + ";\n"
}
}
styleStr += "}\n"
}
xxxxxxxxxx
var obj = {
button: {
css: {
width: "100%",
backgroundColor: "#4CAF50",
border: "none",
color: "red",
padding: "15px 32px",
textAlign: "center",
textDecoration: "none",
display: "inline-block",
fontSize: "16px",
margin: "4px 2px",
cursor: "pointer"
},
attr: {
text: 'Foo'
}
},
a: {
css: {},
attr: {
href: 'http://stackoverflow.com',
text: 'Visit StackOverflow.com'
}
}
}
Object.keys(obj).forEach(function(k) {
$('<' + k + ' />', obj[k].attr).css(obj[k].css).appendTo('#container');
});