开发者

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>

$(fu开发者_如何学Cnction() {
    $('#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?


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

example...

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


This way:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜