JSFiddle - React, Tailwind, and code Playground
HTML
<div>
hi this is one line<br>
<p>This is second line</p>
<p>This 'word' is within quote</p>
<p>Another 'lorem ipsum' in quote</p>
</div>
CSS
.red{
color:red;
}
JavaScript
function replaceText(textToSearch,classToApply)
{
$('div').html($('div').html().replace(new RegExp(textToSearch, 'g'),"<span class='"+classToApply+"'>"+textToSearch+"</span>"));
}
replaceText('line','red')