1

I have code

<div>
    <a href="#"></a> »
    <a href="#"></a> »
    <a href="#"></a> »
    <a href="#"></a> »
    <a href="#"></a>
</div>

How i can disable or delete this simbol - "»" ?

I use this code

text = $('div').html();
text = text.replace('»','');
$('div').html(text);

but hi does not wokr correctly. The last symbol is displaing.

Another way?

Adrift
  • 58,167
  • 12
  • 92
  • 90
john
  • 49
  • 1
  • 3
  • 1
    possible duplicate of [jQuery - replace all instances of a character in a string](http://stackoverflow.com/questions/13574980/jquery-replace-all-instances-of-a-character-in-a-string) – Ram Oct 14 '14 at 21:17

2 Answers2

2

You just need to add the global flag (g) to your replace code like it was a regex:

text = $('div').html();
text = text.replace(/»/g,'');
$('div').html(text);

jsFiddle example

j08691
  • 204,283
  • 31
  • 260
  • 272
2

replace when passed a string only replaces the first instance. You must use a regular expression instead.

http://jsfiddle.net/zkvss6uf/

text = $('div').html();
text = text.replace(/»/g,'');
$('div').html(text);
Jason
  • 4,079
  • 4
  • 22
  • 32