Created
September 1, 2017 11:43
-
-
Save harish2704/c77b4a08676c24654eb908190f020080 to your computer and use it in GitHub Desktop.
Convert / extract all applied styles in DOM element convert it into inline css
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 getCss( elem ){ | |
| var rules = [].slice.call(window.getMatchedCSSRules( elem )); | |
| return rules.map( rule => rule.style.cssText ).join(''); | |
| } | |
| function addInlineCss( elem, isRecurssive ){ | |
| elem.setAttribute( 'style', getCss( elem ) ); | |
| if( isRecurssive && elem.children.length ){ | |
| [].slice.call( elem.children ).forEach( v => addInlineCss(v, true ) ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment