Skip to content

Instantly share code, notes, and snippets.

@thybzi thybzi/createStyle.js
Last active Oct 5, 2016

Embed
What would you like to do?
function createStyle(data, useImportant, w) {
var styleElement, styleContent, selector, property, value;
w = w || window;
styleContent = '';
for (selector in data) {
if (!data.hasOwnProperty(selector)) continue;
styleContent += '\n' + selector + ' {\n';
for (property in data[selector]) {
if (!data[selector].hasOwnProperty(property)) continue;
value = data[selector][property];
styleContent += ' ' + property + ': ' + value;
if (useImportant) {
styleContent += ' !important';
}
styleContent += ';\n'
}
styleContent += ' }\n';
}
styleElement = w.document.createElement('style');
styleElement.textContent = styleContent;
w.document.querySelector('head').appendChild(styleElement);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.