javascript - Move HTML children elements out of parent and remove the parent element -


trying move children outside of parent remove parent in vanilla javascript. current code looks this:

<div class="parent">   <div class="child"></div>   <div class="child"></div> </div> 

desired output:

<div class="child"></div> <div class="child"></div> 

try setting outerhtml property innerhtml property.

const parent = document.queryselector('.parent') parent.outerhtml = parent.innerhtml 

see live demo:

console.log('before change: ', document.queryselector('.container').innerhtml)    const parent = document.queryselector('.parent')  parent.outerhtml = parent.innerhtml    console.log('after change: ', document.queryselector('.container').innerhtml)
<div class="container">    <div class="parent">      <div class="child"></div>      <div class="child"></div>    </div>  </div>


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -