<tspan>文本</tspan>如果没有定义id或类,如何删除文本

<tspan> text </tspan> how to remove text if id or class is not defined?

本文关键字:gt 文本 lt tspan 何删除 删除 定义 如果没有 id 或类      更新时间:2023-12-02

如何通过javascript或jquery从DOM中删除tspan元素?

<tspan >abc.com</tspan>

注意:没有为tspan定义id或class,这个元素是由ajax请求动态提供的。

一般来说,我的问题是如何搜索具有指定文本内容的元素(在我的例子中是tspan)?

我知道:文本选择器,但在这种情况下无法应用。

谢谢:)

使用contains():

$('tspan:contains(abc.com)').remove();

试试这个

$('tspan').not('[id],[class]').text('');​​​​​​​​​

应该把它扔掉吗?

您可以使用filter():

$("tspan").filter(function() {
    return $(this).text() == "abc.com";
}).remove();

:contains()选择器的工作方式几乎相同,但匹配子字符串,这意味着tspan:contains(abc.com)也将匹配内部文本为"foo abc.com bar"的元素,这可能不是您想要的。