Created
July 1, 2022 20:59
-
-
Save Octagon-simon/b78098acfe0126c9671cd176221a0d12 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let highlight = (word) => { | |
| //get web page contents | |
| let str = document.body.innerHTML.toString(); | |
| //search and replace | |
| str = str.replaceAll( new RegExp(word, 'gi'), `<span style='background-color:red;color:#fff'>${word}</span>` ); | |
| //rebuild the webpage | |
| document.body.innerHTML = str; | |
| } | |
| //invoke function | |
| highlight("Simon"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment