Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Created November 13, 2019 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomhodgins/9a308fe490501df96f8abaa42e17adce to your computer and use it in GitHub Desktop.
Save tomhodgins/9a308fe490501df96f8abaa42e17adce to your computer and use it in GitHub Desktop.
function replaceWord(element, target, replacement) {
var iterable = document.createNodeIterator(element, NodeFilter.SHOW_TEXT)
for (var node; node = iterable.nextNode();) {
node.data = node.data.replace(new RegExp(target, 'g'), replacement)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment