Replace words in the body text

find and replace in word 2017 mac
find and replace in word 2018
find and replace word

Is there a way to replace the normal text within a table element that is placed within the body of the HTML?

Like replacing "hello" with "hi"?

Please only use JavaScript without jQuery.

To replace a string in your HTML with another use the replace method on innerHTML:

document.body.innerHTML = document.body.innerHTML.replace('hello', 'hi');

Note that this will replace the first instance of hello throughout the body, including any instances in your HTML code (e.g. class names etc..), so use with caution - for better results, try restricting the scope of your replacement by targeting your code using document.getElementById or similar.

To replace all instances of the target string, use a simple regular expression with the global flag:

document.body.innerHTML = document.body.innerHTML.replace(/hello/g, 'hi');

javascript - Replace words in the body text, To replace a string in your HTML with another use the replace method on innerHTML: document.body.innerHTML = document.body.innerHTML.replace('​hello'  You can find and replace text with special formatting, such as bold or highlight, by using the Format menu. Select View > Navigation Pane. In the Navigation Pane, select the magnifying glass. Select Settings , and then select Advanced Find & Replace. At the top of the dialog box, select Replace.

The function below works perfectly for me:

// Note this *is* JQuery, see below for JS solution instead
function replaceText(selector, text, newText, flags) {
  var matcher = new RegExp(text, flags);
  $(selector).each(function () {
    var $this = $(this);
    if (!$this.children().length)
       $this.text($this.text().replace(matcher, newText));

Here's a usage example:

function replaceAllText() {
  replaceText('*', 'hello', 'hi', 'g');


You can also use do a direct replacement like so:

document.body.innerHTML = document.body.innerHTML.replace('hello', 'hi');

But be careful with it since it may affect the tags, css and scripts as well.

EDIT: As for a pure JavaScript solution use this method instead:

function replaceText(selector, text, newText, flags) {
  var matcher = new RegExp(text, flags);
  var elems = document.querySelectorAll(selector), i;

  for (i = 0; i < elems.length; i++)
    if (!elems[i].childNodes.length)
      elems[i].innerHTML = elems[i].innerHTML.replace(matcher, newText);

Replace body text conflict - JavaScript, var regex = RegExp(word ,"gi"); var string = $('body').html().replace(regex, translation); $('body').html(string);. is there a better way to replace text  Click in the toolbar, then choose Show Find & Replace. In the search field, enter the word or phrase you want to find. Matches are highlighted as you enter text. To find words that match the capitalization you specify, or to restrict search results to the whole words you entered, click, then choose Whole Words or Match Case (or both).

I had the same problem. I wrote my own function using replace on innerHTML, but it would screw up anchor links and such.

To make it work correctly I used a library to get this done.

The library has an awesome API. After including the script I called it like this:

findAndReplaceDOMText(document.body, {
  find: 'texttofind',
  replace: 'texttoreplace'

Find and replace text - Word - Office Support, Go to Home > Replace or press Ctrl+H. Replace. Enter the word or phrase you want to locate in the Find box. Enter your new text in the Replace box. Select Find​  The style ‘Body Text’ is in the default ‘Blank Document’ template in Word, it’s hidden until used. You could make your own style for text paragraphs called whatever you like e.g. ‘Main Text’ ‘Standard Paragraphs’, ‘Alpine Scenery’ or ‘Tommy the Sea Lion’ – the name doesn’t matter.

I ended up with this function to safely replace text without side effects (so far):

function replaceInText(element, pattern, replacement) {
    for (let node of element.childNodes) {
        switch (node.nodeType) {
            case Node.ELEMENT_NODE:
                replaceInText(node, pattern, replacement);
            case Node.TEXT_NODE:
                node.textContent = node.textContent.replace(pattern, replacement);
            case Node.DOCUMENT_NODE:
                replaceInText(node, pattern, replacement);

It's for cases where the 16kB of findAndReplaceDOMText are a bit too heavy.

Find and replace text in Pages on Mac, In Pages on your Mac, search for words, phrases, numbers, and characters in a All visible content in the document—the main body text, headers and footers,  To replace a string in your HTML with another use the replace method on innerHTML: document.body.innerHTML = document.body.innerHTML.replace('hello', 'hi');

Use the default javascript string replace function

var curInnerHTML = document.body.innerHTML;
curInnerHTML = curInnerHTML.replace("hello", "hi");
document.body.innerHTML = curInnerHTML;

How to convert Normal style into Body Text style in Word, Replacing Styles in Word. Word's Replace does a lot more than changing one text block to another. It can find a style and replace with another  You could use the following to replace the first occurrence of a word within the body of the page: var replaced = $("body").html().replace('-9o0-9909','The new string'); $("body").html(replaced); If you wanted to replace all occurrences of a word, you need to use regex and declare it global /g:

Finding and replacing non-printing characters (such , To replace all instances of the Normal style with the Body Text style you would need to: 1. Leave both the Find What and Replace With boxes blank. 2. The replace () method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced. Note: If you are replacing a value (and not a regular expression ), only the first instance of the value will be replaced. To replace all occurrences of a specified value, use the global (g

AppleScript and Pages: Working with Text, In addition to creating new documents, scripts may be called upon to edit existing documents, including locating and replacing words in the main body text. There are three primary ways to insert text into Microsoft Office Word documents: Insert text in a range. Replace text in a range with new text. Use the TypeText method of a Selection object to insert text at the cursor or selection.

Search and Replace Specific Formatting (fonts, styles,etc) in , What you might not realize is that the search and replace functionality in Word allows you to replace more than just text. You can easily search  Method 1: Use “Find and Replace” Feature First and foremost, click “Home” tab. Then click “Replace” in “Editing” group. Next in “Find and Replace” dialog box, make sure you are under “Replace” tab. Put insertion pointer in “Find what” box and ensure it’s blank.

  • Can you please be more specific? What do you want to replace, where is it in the body, etc.
  • the body has a div and within that a table, then i would like to replace some normal text not code like replacing ("hello") with ("hi")
  • most solutions below will destroy all events and the whole dom structure if word being replaced happened to be class name, tag name or anything in html
  • It looks like both question and answers are wrong. It asks how to replace words and not chars. Such as replacement of this hello, this is a text randomTexthello should be hi, this is a text randomTexthello. However, all other answers here replacing the chars instead of words.
  • didnt work for me here is what i used <script type="text/javascript"> window.onload = clear(); function clear() { document.body.innerHTML = document.body.replace('ü', 'n'); } </script>
  • It can be more complicated with extended characters - what encoding is your document in? Are you sure that the character is an ü, and not &#252; for example..?
  • you didn't copy my code accurately ;-) make sure you've got innerHTML on both sides of the statement, i.e: document.body.innerHTML = document.body.innerHTML.replace('ü', 'n');
  • FYI - Bug in the first comment is: set window.onload = clear; without the parentheses "()". When you write clear() then you actually execute the function, but you only want to assign the function to the onload-handler
  • Note that using innerHTML is generally considered bad these days:
  • How would one go about replacing all text in a specific tag (like <p> or <span>) with some other text?
  • Just add the tag name(s) to the first input parameter e.g replaceText('p,span', 'hello', 'hi')
  • This does not work correctly. Consider this: <p>hello <strong>world</strong></p>. hello does not get replaced.
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
  • This is not a new question, I was expanding on funky-future's answer by providing a example that works. had to post a new answer bc I lack rep to comment on his.