javascript - 如何在不删除其子项的情况下删除 div?

标签 javascript jquery dom removeclass

例如http://jsfiddle.net/skpfknxo/

它删除了 div #test 及其子元素 #test2#test3。 我想删除 #test 而不删除它的子项。

这是怎么做到的?

最佳答案

$( "button" ).click(function() {
  $( "#test2" ).unwrap();
});

demo

The .unwrap() method removes the element's parent. This is effectively the inverse of the .wrap() method. The matched elements (and their siblings, if any) replace their parents within the DOM structure.

关于javascript - 如何在不删除其子项的情况下删除 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32919358/

相关文章:

javascript - 获取 HTML 并插入到 DOM 中,但相对于特定路径进行解析

javascript - 编辑器node.js文件上传示例错误 - 上传文件时发生服务器错误

javascript - 什么时候需要转义正则表达式字符集中的字符([] 内)?

javascript - 如何消除子导航重叠?

jquery - 不显示禁用的选项元素?

javascript - jQuery.submit() 是否缩小了 DOM 元素的范围?

javascript - Ionic 创建新的 sass 文件

android - 两个元素,使一个溢出隐藏而另一个寄存器为两个元素滚动?

javascript - 使用 jQuery Select2 清除下拉列表

javascript - jQuery html() 和自闭标签