Remove the parent div, but not what is inside the parent.

Hey, I'm not sure if this is possible, but anyway. Say for example:

<div id="foo"> <a href="#" id="bar">Remove Parent</a> </div> $(function() { $('#bar').click(function() { $(this).parent().remove(); }); }); 

Is it possible that you can remove the parent container in this #foo example, but keep the anchor tag for the child #bar ?

+7
source share
2 answers

In this situation, you would be looking for .unwrap()

Example...

 $(function() { $('#bar').click(function() { $(this).unwrap(); }); }); 
+10
source

Thus:

 $(function() { $('#bar').click(function() { $("#bar").insertAfter("#foo"); }); }); 
0
source

All Articles