Hello see the jsfiddle here : http://jsfiddle.net/moolood/jU9QY/
var toto = 'bien_address_1=&bien_cp_1=&bien_ville_1=';
var tata = toto.replace('&','<br/>');
$('#test').append(tata);
Why Jquery in my exemple only found one '&' and replace it?
Hello see the jsfiddle here : http://jsfiddle.net/moolood/jU9QY/
var toto = 'bien_address_1=&bien_cp_1=&bien_ville_1=';
var tata = toto.replace('&','<br/>');
$('#test').append(tata);
Why Jquery in my exemple only found one '&' and replace it?
Because that's how replace
works in JavaScript. If the search argument is a string, only the first match is replaced.
To do a global replace, you have to use a regular expression with the "global" (g
) flag:
var tata = toto.replace(/&/g,'<br/>');
The code that you have written will only replace the first instance of the string.
Use Regex
along with g will replace all the instances of the string.
toto.replace(/&/g,'<br/>');