Created
February 26, 2026 10:28
-
-
Save erkobridee/5cde215dea145a7839bb633340084255 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
| // ref.: https://plainjs.com/javascript/manipulation/unwrap-a-dom-element-35/ | |
| /** | |
| * unwrap the content of a given HTMLElement to the parent element at the previous | |
| * position of the given element | |
| * | |
| * @param {HTMLElement} element | |
| * @param {boolean} removeElement | |
| */ | |
| export const unwrap = (element: HTMLElement, removeElement = true) => { | |
| const parentNode = element.parentNode; | |
| if (!parentNode) return; | |
| while (element.firstChild) parentNode.insertBefore(element.firstChild, element); | |
| if (removeElement) parentNode.removeChild(element); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment