Skip to content

Instantly share code, notes, and snippets.

View jiayihu's full-sized avatar
:octocat:
Nyaning in O(1)

Jiayi Hu jiayihu

:octocat:
Nyaning in O(1)
View GitHub Profile
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));
});