Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

json to css converter

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("
");
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #json #css #converter
ADD COMMENT
Topic
Name
9+7 =