如何在不删除其子项的情况下删除 div?
How to remove a div without removing its children?
例如http://jsfiddle.net/skpfknxo/
它删除了 div #test
及其子项 #test2
和 #test3
。
我想删除 #test
而不删除其子项。
这是怎么做到的?
$( "button" ).click(function() {
$( "#test2" ).unwrap();
});
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.
例如http://jsfiddle.net/skpfknxo/
它删除了 div #test
及其子项 #test2
和 #test3
。
我想删除 #test
而不删除其子项。
这是怎么做到的?
$( "button" ).click(function() {
$( "#test2" ).unwrap();
});
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.