-3

I have word "john" used many times in my document which I want to replace with "mike". How can I achieve that using Jquery?

0

2 Answers 2

0

Something like that:

var replaced = $("body").html().replace(/John/g,'Mike');
$("body").html(replaced);

Source: Replace text in HTML page with jQuery

Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

One problem with this, it will completely wipe out all the HTML within the body element...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.