Question: 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**.

Answer: 
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');
}

$(document).ready(replaceAllText);
$('html').ajaxStop(replaceAllText);

```

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);
}

```
I was trying to replace a really large string and for some reason regular expressions were throwing some errors/exceptions. 

So I found this alternative to regular expressions which also runs pretty fast. At least it was fast enough for me: 

```
var search = "search string";
var replacement = "replacement string";

document.body.innerHTML = document.body.innerHTML.split(search).join(replacement)

```

src: [How to replace all occurrences of a string in JavaScript?](https://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string-in-javascript)