【发布时间】:2013-02-20 09:20:42
【问题描述】:
<div class="parent">
<span>sometext</span>
plain text
<input class="child">
</div>
<div class="parent">
<span>sometext</span>
plain text
<input class="child">
</div>
<div class="parent">
<span>sometext</span>
plain text
<input class="child">
</div>
如何安全地删除.parent 中除.child 之外的所有内容?
我正在使用此代码(其中items 是.child 的堆栈,each 是.child)
items.each(function(){
$(this).parent().children().each(function(){
if ($(this).hasClass('child'))
// do something
else
$(this).remove();
});
$(this).unwrap(); // remove parent, keep only .child
});
但它不处理纯文本。
【问题讨论】:
标签: javascript jquery html parent children