I have word "john" used many times in my document which I want to replace with "mike". How can I achieve that using Jquery?
2 Answers
Something like that:
var replaced = $("body").html().replace(/John/g,'Mike');
$("body").html(replaced);
Comments
$("body").text(function () {
return $(this).text().replace("john", "mike");
});
This would work if you need to change any text found in the body element.
1 Comment
Rory McCrossan
One problem with this, it will completely wipe out all the HTML within the
body element...