Skip to content

Instantly share code, notes, and snippets.

@djoeman84
Last active April 10, 2017 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djoeman84/b45c18d57f724b118f8906a53be43500 to your computer and use it in GitHub Desktop.
Save djoeman84/b45c18d57f724b118f8906a53be43500 to your computer and use it in GitHub Desktop.
Quick CSS setter
function stylePage(d){
for (var selector in d) {
if (!d.hasOwnProperty(selector)) return;
var properties = d[selector];
for (var styleName in properties) {
if (!properties.hasOwnProperty(styleName)) return;
var style = properties[styleName];
var matching = document.querySelectorAll(selector);
for (var j = 0; j < matching.length; j++) {
matching[j].style[styleName] = style;
}
}
}
}
/*
Example:
stylePage({
'.my-class child': {
color: 'red',
},
})
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment