删除< span>之后的文字并附加其他文字 [英] Remove text after <span> and append other text

查看:59
本文介绍了删除< span>之后的文字并附加其他文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了jQuery试图在<之后删除文本的问题。 span>标记以附加其他文本。

I'm having a trouble with jQuery trying to remove a text after < span> tag to append other text.

示例:

<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');

但是如何删除/清除< / span>标签添加一个新的?

But how can I remove/clear the text after < /span> tag to append a new one?

推荐答案

假设中没有其他文本节点#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>

这篇关于删除&lt; span&gt;之后的文字并附加其他文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆