I wanna replace several words in a text using replace()
in javascript, how can I do that?
For example, if I wanna replace, \'Dave Chambers,
You'll want to use regular expressions if you want to ignore case:
var str = sometext.innerHTML;
str.replace(/Dave Chambers/ig, 'Jackie Chan')
.replace(/David Chambers/ig, 'Jackie Chan')
.replace(/Will Smith/ig, 'Jackie Chan');
You can do it all in one statement like above and that's how I would prefer as it's more readable.