JSFiddle - React, Tailwind, and code Playground
HTML
<div class="container">
<div id="wrapper"><span>Some</span> content</div>
<div>More content</div>
</div>
<button id="unwrap">Unwrap</button>
CSS
#container {
border: 1px solid black;
padding: 5px;
}
#wrapper {
border: 2px solid red;
padding: 5px;
}
JavaScript
function unwrap(element) {
// insert all the element's children *after* the element itself
var parent = element.parentNode;
var children = element.childNodes;
var before = element.nextSibling;
// reverse iteration always inserting the previous sibling before
// the next one
for (var i = children.length - 1; i > -1; i--) {
before = parent.insertBefore(children[i], before);
}
// remove the element
parent.removeChild(element);
}
document.getElementById('unwrap').onclick = function() {
var element = document.getElementById('wrapper');
if (element) {
unwrap(element);
}
};