Skip to content

Instantly share code, notes, and snippets.

@fmontes
Created August 23, 2018 18:15
Show Gist options
  • Save fmontes/48c2d07c2ceb3ab195224e69429b1e9c to your computer and use it in GitHub Desktop.
Save fmontes/48c2d07c2ceb3ab195224e69429b1e9c to your computer and use it in GitHub Desktop.
Find and replace text in a webpage
// Find all the existence of a text:
var headings = document.evaluate("//h4[contains(., 'String of text')]", document, null, XPathResult.ANY_TYPE, null );
// Get one element
var el = headings.iterateNext();
// Replace the text
el.innerText = 'New text'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment