Created
April 3, 2019 12:39
-
-
Save ccapndave/910245a70171f45d1bd76140d4256992 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 removeAndReinsert(element: Element) { | |
const parent = element.parentNode; | |
if (parent.childElementCount > 1) { | |
const nextSibling = element.nextSibling; | |
parent.removeChild(element); | |
parent.insertBefore(element, nextSibling) | |
} else if (parent.childElementCount === 1) { | |
parent.removeChild(element); | |
parent.appendChild(element); | |
} else { | |
throw new Error("wedr insisted I put this in"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment