Created
May 13, 2017 14:27
-
-
Save nikitaeverywhere/53e30f4b7bd067b93a38690227860c08 to your computer and use it in GitHub Desktop.
Deep node clone node with styles cloning
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 deepCloneWithStyles (node) { | |
const style = window.getComputedStyle(document.body, null); | |
const clone = node.cloneNode(false); | |
if (clone.style && style.cssText) | |
clone.style.cssText = style.cssText; | |
for (let child of node.childNodes) | |
clone.appendChild(deepClone(child)); | |
return clone; | |
} |
i believe its supposed to be a recursive function. "deepClone" should be "deepCloneWithStyles".
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As it was 6 years ago and to give you a more qualified answer, can you remind me how did you land on this page? How did you find out this snippet?
Thanks @kiran-venugopal-bs .