Skip to content

Instantly share code, notes, and snippets.

@ka7eh
Created December 8, 2016 00:00
Show Gist options
  • Save ka7eh/4ac499c31ae3c2719207e23e0fe6a16e to your computer and use it in GitHub Desktop.
Save ka7eh/4ac499c31ae3c2719207e23e0fe6a16e to your computer and use it in GitHub Desktop.
Convert styling rules of an element into inline styling
function cssInliner(el) {
var cssProperties = getComputedStyle(el, null);
var cssText = '';
for (var i = 0; i < cssProperties.length; i++) {
cssText += cssProperties[i] + ':' + cssProperties.getPropertyValue(cssProperties[i]) + ';'
}
el.style.cssText = cssText;
for (var j = 0; j < el.childElementCount; j++) {
cssInliner(el.children[j]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment