删除链接,如果链接名称包含字符串

问题描述:

我有我的网页上的链接列表。这里有一个例子:删除链接,如果链接名称包含字符串

<a href="#">Link (tagMe)</a> 
<a href="#">Link (anotherTag)</a> 
<a href="#">Link (aThirdTag)</a> 

如何获取jQuery来检查我的所有链接,并删除了一个字符串“(anotherTag)”,所以输出列表看起来像:

  • 链接(塔格梅)
  • 链路(aThirdTag)
+0

可能重复(http://*.com/questions/2446936/how-to- select-all-anchor-tags-with-specific-text) – undefined 2013-04-24 04:15:03

您可以使用:contains选择器。

$('a:contains("anotherTag")').remove(); 

http://jsfiddle.net/BbyWB/

+0

这就做到了。谢谢! – 2013-04-24 04:26:17

$('a').each(function() { 
    if($(this).text().match(/\(anotherTag\)/)) 
     $(this).remove(); 
}); 

http://jsfiddle.net/samliew/wLM5q/1/

$("a:contains('anotherTag')").remove() 

jsFiddle

的[如何选择具有特定文本的所有锚标签]