Created
December 8, 2016 00:00
-
-
Save ka7eh/4ac499c31ae3c2719207e23e0fe6a16e to your computer and use it in GitHub Desktop.
Convert styling rules of an element into inline styling
This file contains hidden or 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 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