I have a div structure like this
<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
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
or use the cloning method and eventdelegate you kendo controls
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()
var el = $('#parent-conatiner').detach();
$('body').empty().append(el);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.