unwrap
The unwrap method is used to remove the outer wrapper element of the target element.
I am target
Notes
The target element must have a parent node, otherwise the unwrap operation cannot be performed.
const $el = $(`
<div>
<div id="target"></div>
</div>
`);
$el.unwrap(); // Error, no parent element, cannot unwrap
$el.$('#target').unwrap(); // Correct, remove the wrapping element
When the target element has sibling elements, unwrap cannot be performed either.
const $el = $(`
<div>
<div id="target"></div>
<div>I am siblings</div>
</div>
`);
$el.$('#target').unwrap(); // Error, because it has adjacent siblings
Please note, do not operate within template components such as o-fill or o-if.