0

i want replace the symbol "_" with a space in a div class,

this is a example :

<div class="textreply">

my_names_is_mark

</div>

i want replace with this :

 <div class="textreply">

    my names is mark

</div>

i have already build 2 script like this :

1:

   jQuery(document).ready(function(){

jQuery(".textreply").text(function () {
    return jQuery(this).text().replace("_", "  "); 
});          });  

2:

$('.textreply').each(function() {
    var text = $(this).text();
    $(this).text(text.replace('_', ' ')); 
}); 

the problem with this 2 script is to replaced only the first "_" of word

example this :

my names_is_mark

and not continue .

how replace every "_" ?

SURTLER77
  • 87
  • 1
  • 16
  • 1
    Possible duplicate of [Why does javascript replace only first instance when using replace?](http://stackoverflow.com/questions/1967119/why-does-javascript-replace-only-first-instance-when-using-replace). Demo: http://jsfiddle.net/2750xoke/ – blex Aug 23 '15 at 18:29

1 Answers1

1

change

replace('_', ' ')

to

replace(/_/g, ' ')
adam.pilacki
  • 101
  • 6