jQuery删除h1文本

时间:2012-11-27 14:53:35

标签: jquery text

我有这个HTML行:

<nobr title="New" class="testClass">
       <h1>ABC</h1>
</nobr>

如何删除h1中的文本或删除整个h1标签?

我的最后一次尝试:

$("nobr.testClass > h1").text('');

但是这不起作用

3 个答案:

答案 0 :(得分:6)

以下内容删除了h1元素:

$("nobr.testClass > h1").remove();

尽管如此,您的代码应该按照书面形式运行。你的错误在其他地方。

答案 1 :(得分:4)

试试这个:

   $(".testClass h1").text('');

并删除:

   $(".testClass h1").remove();

答案 2 :(得分:2)

删除标记

$("nobr.testClass > h1").remove();

清空标签

$("nobr.testClass > h1").empty();
相关问题