Skip to content

Instantly share code, notes, and snippets.

@ahmadmilzam
Created October 9, 2017 09:38
Show Gist options
  • Save ahmadmilzam/5a2f3b25eb8a28c09a3cd28e9a7df26c to your computer and use it in GitHub Desktop.
Save ahmadmilzam/5a2f3b25eb8a28c09a3cd28e9a7df26c to your computer and use it in GitHub Desktop.
// remove parent without removing childen
function unwrap(wrapper) {
// place childNodes in document fragment
var docFrag = document.createDocumentFragment();
while (wrapper.firstChild) {
var child = wrapper.removeChild(wrapper.firstChild);
docFrag.appendChild(child);
}
// replace wrapper with document fragment
wrapper.parentNode.replaceChild(docFrag, wrapper);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment