Search
 
SCRIPT & CODE EXAMPLE
 

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("
");
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Backbone Sync Example 
Javascript :: javascript Least prime factor of numbers till n 
Javascript :: Backbone Models In Collection Is Added Here 
Javascript :: calculate avg count from month in year js 
Javascript :: javascript reduce mdn 
Javascript :: Backbone Initialize vs Render 
Javascript :: react axios project importing online same products with table from fake API 
Javascript :: refreshapex 
Javascript :: 404 error firebase react js 
Javascript :: how to get header in node controller 
Javascript :: List content on thee currentwdr 
Javascript :: Component With Both Data And Props 
Javascript :: delete all document fragments js 
Javascript :: change background ternary operator jquery 
Javascript :: convert bytes to kb or mb javascript 
Javascript :: react-inline-script 
Javascript :: how to create session cookie in node js 
Javascript :: how to add header to axios request 
Javascript :: añadir input file a formdata javascript 
Javascript :: canvas squashed video javascript 
Javascript :: translate javascript to english 
Javascript :: load content on user language in javascript 
Javascript :: rotate image javascript base64 
Javascript :: Plumsail change the size of the dialog window 
Javascript :: multiple variables in one live javascript 
Javascript :: pass mltiple valuesthorugh context in react 
Javascript :: getting xml from response, make sure server returns valid xml and the "content-type" header is set 
Javascript :: call method from parent 
Javascript :: Angular js set default tab with ng-repeat in array object 
Javascript :: .push( ) is not updating the variable 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =