Replacing Text in HTML with JavaScript
javascript, replace
Solution
Simple regular expression to fix it:
document.body.innerHTML = document.body.innerHTML.replace(/target string/g, "replacement string");
Problem
I'm trying to write a JavaScript program without the use of jQuery to replace all visible target text on a webpage without messing up the page's functionality. Specifically I'm trying to make a Chrome extension that does it passively on sites such as Facebook. I've experienced limited success with the following: ``` checkLoad(); function checkLoad(){ if (document.readyState === "complete") { document.body.innerHTML = document.body.innerHTML.replace("target string", "replacement string"); } else { setTimeout('checkLoad();', 500) } } ``` This code misses things like people's names, titles and such. I've looked around and can't seem to find a working solution. Any ideas?