[英]how to remove all the parent div using jQuery
I have a div structure like this 我有这样的div结构
<body>
<div>
<nav></nav>
<nav></nav>
<div>
<div id=parent-conatiner>
<div>
<ul>
<li></li>
<li></li>
</ul>
</div>
</div>
</div>
</div>
</body>
now i want to remove all the parent element of the div #parent-container but not removing any element inside the #parent-container div, i dont want to use clone and then include the element in the body because i use some kendo controls inside the #parent-container and the kendo controls stopped working when i use the cloned div basically i dont want to use the following logic 现在我想删除div #parent-container的所有父元素,但不删除#parent-container div中的任何元素,我不想使用clone然后在body中包含元素,因为我在里面使用了一些kendo控件当我使用克隆的div时,#parent-container和kendo控件停止工作基本上我不想使用以下逻辑
var $cloned=$('#parent-conatiner')
$('body').empty();
$('body').append($cloned);
any help would be appreciated, thank you 任何帮助将不胜感激,谢谢
使用以下方法,所有事件绑定都保持不变。
$('#parent-conatiner').parentsUntil('body').replaceWith($('#parent-conatiner'));
Use the jquery unwrap()
function 使用jquery
unwrap()
函数
or use the cloning method and eventdelegate you kendo controls 或使用克隆方法和eventdelegate kendo控件
another solution will be: 另一种解决方案是:
$('body').append($('#parent-conatiner'));
$('body div:last').prevAll().remove();
but this should be the same problem like the cloning 但这应该是像克隆一样的问题
another option is detach() 另一个选择是detach()
var el = $('#parent-conatiner').detach();
$('body').empty().append(el);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.