jQuery的删除与此链接后一定标签和整个文本链接
问题描述:
<a href="/" title="Go to homepage">Homepage</a> text after link;
<a href="/" title="About">About</a> text after link;
<a href="/" title="Contact Us">Contact Us</a> text after link;
没有问题:我可以删除该链接:
$("a:contains('Homepage')").remove();
我的问题:如何去除链接后的文本以前删除:
text after link
在此先感谢。
答
您可以设置文本节点的值清空,就像这样:
$("a:contains('Homepage')")[0].nextSibling.nodeValue = "";
You can try it here。如果您不确定它是否存在,请添加if
支票,如下所示:
var node = $("a:contains('Homepage')")[0];
if(node && node.nextSibling) node.nextSibling.nodeValue = "";
令人惊讶的是,它的工作原理。谢谢尼克。 – josoroma 2010-07-19 02:54:35
@josoroma - 欢迎:) – 2010-07-19 02:55:45