JSFiddle - React, Tailwind, and code Playground
HTML
<div class="matchedOn">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit magnam inventore tenetur consequuntur sint sunt animi sequi aliquam? Ipsam voluptate nam deserunt voluptatem odio omnis molestias beatae quae nisi cum.
</div>
JavaScript
var matchedString = 'ipsum';
var match = $('.matchedOn:contains("' + matchedString + '")');
match.html(match.html().replace(matchedString, "<span style='background-color:#FFFF00'>" + matchedString + "</span>"));
alert('first iteration');
var matchedString = 'dolor';
var match = $('.matchedOn:contains("' + matchedString + '")');
match.html(match.html().replace(matchedString, "<span style='background-color:#FFFF00'>" + matchedString + "</span>"));