JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" />
<div>
<p>Apple</p>
<p>Peach</p>
<p>Bannana</p>
<p>Tomato</p>
</div>
JavaScript
var items = $("div").find("p");
function escapeReg(str) {
return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}
$('input').on('keyup', function() {
var reg = new RegExp('(' + escapeReg(this.value)+ ')', 'gi');
items.text(function(_, text) { return text }).each(function() {
return $(this).html(function(_, html) {
return html.replace(reg, "<b>$1</b>");
})
})
})
console.log(items);