Last active
April 10, 2017 16:28
-
-
Save djoeman84/b45c18d57f724b118f8906a53be43500 to your computer and use it in GitHub Desktop.
Quick CSS setter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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