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: removes the wrapping element
When the target element has other sibling elements, unwrap cannot be executed either.
const $el = $(`
<div>
<div id="target"></div>
<div>I am siblings</div>
</div>
`);
$el.$('#target').unwrap(); // Error, because it has other sibling nodes
Please note, do not operate inside template components such as o-fill or o-if.