JSFiddle - React, Tailwind, and code Playground
by mattography
HTML
<input type="text" id="searchfor" />
<p id="all_text">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</p>
CSS
#all_text span {
text-decoration:underline;
background-color:yellow;
}
JavaScript
$('#searchfor').highlight("#all_text")(function () {
var page = $('#all_text');
var pageText = page.text().replace("<span>", "");
var searchedText = $('#searchfor').val();
var theRegEx = new RegExp("(" + searchedText + ")", "igm");
var newHtml = pageText.replace(theRegEx, "<span>$1</span>");
page.html(newHtml);
});