删除父Div,但不删除父内容。 [英] Remove the Parent Div, but not what's inside the parent.
本文介绍了删除父Div,但不删除父内容。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< div id =foo>
< a href =#id =bar>删除父级< / a>
< / div>
$(function(){
$('#bar')。click(function(){
$(this).parent()。remove();
});
});
您是否可以删除父容器,在此示例中# foo
但保留子锚标签 #bar
?
解决方案
在这种情况下,你一直在寻找 .unwrap()
示例...
$(function(){
$('#bar')。click(function(){
$(this).unwrap();
});
});
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
?
解决方案
In this situation you'd be looking for .unwrap()
example...
$(function() {
$('#bar').click(function() {
$(this).unwrap();
});
});
这篇关于删除父Div,但不删除父内容。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文