Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove the Parent Div, but not what's 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 example #foo but keep the child anchor tag #bar?

like image 824
daryl Avatar asked Mar 05 '11 05:03

daryl


1 Answers

In this situation you'd be looking for .unwrap()

example...

$(function() {
    $('#bar').click(function() {
        $(this).unwrap();
    });
});
like image 162
jondavidjohn Avatar answered Nov 10 '22 06:11

jondavidjohn