删除包装的div并保留所有子div不变? [英] remove wrapping div and leave all sub-divs intact?
问题描述
我有一个包装器div,内部有几个子div,在这些子div中也有标签.我想删除包装div.我已经考虑过JQuery的展开,但是似乎我需要指定子div来告诉Jquery要展开的内容.如果有几个孩子,这会工作吗?
I have one wrapper div with several sub-divs inside and tags inside those sub-divs as well. I want to remove the wrapper div. I have considered JQuery's unwrap, but it appears as though I need to specify the child divs to tell Jquery what to unwrap. Will this work if there are several children?
因此,代码如下:
<div id="wrapper">
<div id="innerDiv1"></div>
<div id="innerDiv2"></div>
<div id="innerDiv3"></div>
</div>
我们将一如既往地为您提供帮助.
Any help, as always, is appreciated.
谢谢.
推荐答案
unwrap
方法可以正常工作(您可以可以选择任何/任何数量的兄弟姐妹):
The unwrap
method will work fine (you can select any of/any number of the siblings):
$("#innerDiv1").unwrap();
从文档中(添加重点):
From the docs (emphasis added):
匹配的元素(及其同级元素,如果有的话)替换了它们 DOM结构中的父级.
The matched elements (and their siblings, if any) replace their parents within the DOM structure.
这篇关于删除包装的div并保留所有子div不变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!