I would like to remove the parent without removing the child - is this possible?
HTML structure:
<div class="wrapper">
<img src"">
</div>
<div class="button">Remove wrapper</div>
After clicking on the button I would like to have:
<img src"">
<div class="button">Remove wrapper</div>
Pure javascript solution, i'm sure someone can simplify it more but this is an alternative for pure javascript guys.
HTML
Javascript (pure)
JSFIDDLE
Pure JS solution that doesn't use innerHTML:
Try it:
If the wrapper element contains text, the text remains with child nodes.
Pure JS (ES6) solution, in my opinion easier to read than jQuery-solutions.
node has to be an ElementNode
Could use this API: http://api.jquery.com/unwrap/
Demo http://jsfiddle.net/7GrbM/
.unwrap
Code will look something on these lines:
Sample Code
if you're using jQuery: