/html-dom /Basic
GitHub 4932★

Wrap an element around a given element

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);

See also

Follow me on and to get more useful contents.