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; | |
} |
@PlopTheReal thank you!
what is deepClone
here in line 7?
what is deepClone here in line 7?
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 .
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
Heya!
I was looking at this and I wonder how deepClone() looks like ;)
Many thanks!