我在 jQuery 尝试删除 标记后的文本以附加其他文本时遇到问题。
Example:
<div id="foo-id">
<span id="span-id">
<i id="icon-id" class="fa fa-square-o"></i>
</span> text..here... (this text needs to be removed)
</div>
我知道如何附加文本:
$('#foo-id').after()[0].append('this is a text');
但是如何删除/清除 标记后的文本以附加新的文本?
假设直接内部没有其他文本节点#foo-id
你可以这样做:
$('#foo-id').html(function(){
return $(this).children(); //only return elements, not text nodes
}).append('Some new text')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="foo-id">
<span id="span-id">
<i id="icon-id" class="fa fa-square-o"></i>
</span> text..here... (this text needs to be removed)
</div>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)