JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<span>This</span>
<span>Example</span>.
<div> Here is my example text. I will be looking to highlight the word <span class="blue-underline">example.</span> </div>
</body>
CSS
.highlight {
background-color: yellow;
}
.blue-underline{
border-bottom: 1px solid blue;
}
JavaScript
let target = 'example';
var text = document.querySelector('body').textContent;
var regex = new RegExp('(' + target + ')', 'ig');
const newtext = text.replace(regex, '<a href="#" class="highlight">$1</a>');
text.innerHTML = newtext;