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 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
Matt Coady
  • 3,418
  • 5
  • 38
  • 63

2 Answers2

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

http://jsfiddle.net/EgHkr/

Ram
  • 143,282
  • 16
  • 168
  • 197
  • @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