Skip to content

Instantly share code, notes, and snippets.

Created October 29, 2017 04:28
Show Gist options
  • Save anonymous/082caa01aef5b8d2aa0c7f2fa8110efb to your computer and use it in GitHub Desktop.
Save anonymous/082caa01aef5b8d2aa0c7f2fa8110efb to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Oct 29, 2017.
    14 changes: 14 additions & 0 deletions domCopyChildrenExcept.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@

    // copy current children except a certain child while keeping all refs - a pain in the ass.

    let i = oldParent.childNodes.length - 1
    for (; i >= 0; i -= 1) {
    const c = oldParent.childNodes[i]

    // whatever, your condition here
    if (c.nodeName.toLowerCase() !== "slot") {
    newParent.appendChild(c)
    }
    }

    // use var instead of let and const for <ES6