This question already has an answer here:
This does not work and I need it badly
$('some+multi+word+string').replace('+', ' ' );
always gets
some multi+word+string
it's always replacing for the first instance only, but I need it to work for all + symbols.
RegEx is the way to go in most cases.
In some cases, it may be faster to specify more elements or the specific element to perform the replace on:
This does the replace once on each string, but it does it using a more specific selector.
'g' = "global"
Cheers
You need to use a regular expression, so that you can specify the global (g) flag:
(I removed the
$()
around the string, asreplace
is not a jQuery method, so that won't work at all.)