I have word "john" used many times in my document which I want to replace with "mike". How can I achieve that using Jquery?
Asked
Active
Viewed 538 times
2 Answers
0
$("body").text(function () {
return $(this).text().replace("john", "mike");
});
This would work if you need to change any text found in the body element.

Monroy
- 420
- 5
- 19
-
One problem with this, it will completely wipe out all the HTML within the `body` element... – Rory McCrossan Mar 09 '16 at 19:53
0
Something like that:
var replaced = $("body").html().replace(/John/g,'Mike');
$("body").html(replaced);