Skip to content

Instantly share code, notes, and snippets.

@nikitaeverywhere
Created May 13, 2017 14:27
Show Gist options
  • Save nikitaeverywhere/53e30f4b7bd067b93a38690227860c08 to your computer and use it in GitHub Desktop.
Save nikitaeverywhere/53e30f4b7bd067b93a38690227860c08 to your computer and use it in GitHub Desktop.
Deep node clone node with styles cloning
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;
}
@noodlebenji2960
Copy link

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