JSFiddle - React, Tailwind, and code Playground
HTML
<p class="para">
My house is red and my front door is blue.
</p>
CSS
.matched {
background-color: red;
font-weight: bold;
}
JavaScript
(function() {
var paragraph = document.getElementsByClassName('para')[0];
var text = paragraph.innerHTML;
var wordArr = text.split(' ');
text = [];
wordArr.forEach(function(el) {
if(el === 'house' || el === 'red')
el = '<span class="matched">' + el + '</span>';
text.push(el);
});
console.log(text);
text = text.join(' ');
paragraph.innerHTML = text;
})()