0

I've got a list of links that looks like this

  • Item 1
  • Item 2 (foo)
  • Item 3

How do I get jQuery to remove the string " (foo)" from the link text?

Derek 朕會功夫
  • 88,688
  • 41
  • 174
  • 241
Matt Coady
  • 2,834
  • 5
  • 35
  • 58

2 Answers2

3
$('a:contains(foo)').text(function(_, currentText){
   return currentText.replace('foo', '');
});

http://jsfiddle.net/EgHkr/

Ram
  • 140,563
  • 16
  • 160
  • 190
  • @Derek朕會功夫 Well it's not a special keyword. http://stackoverflow.com/questions/1661197/valid-characters-for-javascript-variable-names – Ram Apr 24 '13 at 05:03
0

another alternative

$('li:nth-child(2)').replaceWith('<li>Item 2</li>');
esorbma
  • 58
  • 6