js-to-css

1.0.2 • Public • Published

js-to-css

css = js_to_css({
    "body": {
        "background-color": "blue",
        div: {
            "background-color": "green"
        }
    },
    "#test": {
        "background-color": "yellow"
    }
});
 

This returns a multi-line string, converted here to css.

body {background-color: blue; }  
body div {background-color: green; }  
#test {background-color: yellow; }  

Then we add the css string to the dom. You can also add it to an element, or do with it what ever you'd like.

Below comes from: http://stackoverflow.com/questions/11371550/change-hover-css-properties-with-javascript

style = document.createElement('style');
if (style.styleSheet) {
    style.styleSheet.cssText = css;
} else {
    style.appendChild(document.createTextNode(css));
}
document.getElementsByTagName('head')[0].appendChild(style);

Issues, requests, stars:

https://github.com/tyler-r-smith/js-to-css

Readme

Keywords

Package Sidebar

Install

npm i js-to-css

Weekly Downloads

67

Version

1.0.2

License

MIT

Last publish

Collaborators

  • tylerrsmith