删除除DIV中的按钮以外的所有HTML [英] Remove all HTML others than button inside a DIV
本文介绍了删除除DIV中的按钮以外的所有HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从DIV中删除所有内容(动态创建),但不删除默认情况下存在的按钮.这是HTML:
I need to remove all the content (created dynamically) from a DIV but not a button that exists by default. This is the HTML:
<div id="{{ entity.getLabel|lower ~ "_choice_" ~ entity.getId }}" style="display: none">
<button type="button" class="add-size">Adicionar {{ entity.getLabel|lower }}</button>
</div>
我正在按照以下步骤进行操作:
And I'm doing as follow:
$("#" + theName + '_choice_' + theID).empty();
$("#" + theName + '_choice_' + theID).hide();
当然vars取其适当的值,我只是强硬地.empty()
删除了所有内容,我需要离开按钮,我该怎么做?
Of course the vars takes their proper values I just tough .empty()
removes all and I need to leave the button, how I do that?
PS:在这两种情况下,HTML和jQuery代码都忘记了vars和Twig标签,因为它可以完成工作,我只需要用$.empty()
代替某些工作代码
PS: In both cases HTML and jQuery code forget about vars and Twig tags since it does the job I just need to replace $.empty()
for some working code
推荐答案
$("#" + theName + '_choice_' + theID).find(':not(button)').remove();
这篇关于删除除DIV中的按钮以外的所有HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文