
Wrap the wrapper
element around the ele
element:
// First, insert `wrapper` before `ele` in its parent node
ele.parentNode.insertBefore(wrapper, ele);
// And then, turn `ele` into a children of `wrapper`
wrapper.appendChild(ele);
Source
https://htmldom.dev/wrap-an-element-around-a-given-element