var elements = document.getElementsByTagName('*'); for (var i = 0; i < elements.length; i++) { var element = elements[i]; for (var j = 0; j < element.childNodes.length; j++) { var node = element.childNodes[j]; if (node.nodeType === 3) { var text = node.nodeValue; var replacedText = text.replace(/[word or phrase to replace here]/gi, '[new word or phrase]'); if (replacedText !== text) { element.replaceChild(document.createTextNode(replacedText),node); } } } } This script should make words and replace them with others (this script is for expansion). Please help to remake it so that it changes the color of the replaced words, say red.