jQuery删除除第一个元素外的所有元素 [英] jquery remove all elements except for first one
本文介绍了jQuery删除除第一个元素外的所有元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用jquery删除如何删除除第一个之外的所有span标签.
Using jquery remove how can i remove all the span tags except for the first one..
EDIT
var html = var htm = $("#addin").find(".engagement_data:last-child").find(".keys_values").html();
html='
<span style="display:block;" class="k_v">
<innput type="text" class="e_keys" style="width:65px;" placeholder="key"/>
<input type="text" class="e_values" style="width:65px;" placeholder="value"/>
</span>
<span style="display:block;" class="k_v">
<input type="text" class="e_keys" style="width:65px;" placeholder="key"/>
<input type="text" class="e_values" style="width:65px;" placeholder="value"/>
</span>
';
推荐答案
尝试使用:
$(html).not(':first').remove();
或更具体地说:
$(html).not('span:first').remove();
要从DOM中删除它,而不要使用html
变量,请使用选择器:
To remove it from DOM, instead of html
variable, use your selector:
$('#addin .engagement_data:last-child .keys_values').not('span:first').remove();
这篇关于jQuery删除除第一个元素外的所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文