How can I remove wrapper (parent element) without removing the child?

后端 未结 7 1231
天命终不由人
天命终不由人 2020-12-03 20:48

I would like to remove the parent without removing the child - is this possible?

HTML structure:

7条回答
  •  独厮守ぢ
    2020-12-03 21:42

    Surprised that nobody's posting the simplest answer:

    // Find your wrapper HTMLElement
    var wrapper = document.querySelector('.wrapper');
    
    // Replace the whole wrapper with its own contents
    wrapper.outerHTML = wrapper.innerHTML;
    

提交回复
热议问题