JSFiddle - React, Tailwind, and code Playground

by Derek Anderson

HTML

<div>John Resig</div>
<div>George Martin</div>
<div>Malcom John Sinclair</div>
<span>John doe</span>

CSS

span.highlight{background-color:yellow;}

JavaScript

(function(){
    var tpoem = window.tpoem || function(){};
    tpoem.hlite = function(htmlelement, term, htmlclass){
        var re = new RegExp(term,"gi");
        var body =  document.getElementsByTagName(htmlelement)[0];
        var html = '<span class="' + htmlclass + '">' + term + '</span>';                    
        body.innerHTML = body.innerHTML.replace(re,html);
    }
    window.tpoem = tpoem;
})();

tpoem.hlite('body','John','highlight');