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 copyStyles(sourceDoc, targetDoc) { | |
Array.from(sourceDoc.styleSheets).forEach(styleSheet => { | |
if (styleSheet.cssRules) { // for <style> elements | |
const newStyleEl = sourceDoc.createElement('style'); | |
Array.from(styleSheet.cssRules).forEach(cssRule => { | |
// write the text of each rule into the body of the style element | |
newStyleEl.appendChild(sourceDoc.createTextNode(cssRule.cssText)); | |
}); |