JSFiddle - React, Tailwind, and code Playground

by zahirdhada

HTML

<div id="theWord">tjurkey</div>

CSS

.highlight
{
    color:green;
}

JavaScript

var t = "";
var word = $("#theWord").text();
   $("body").keypress(function (e) {
       if (e.which !== 0) {
           t += String.fromCharCode(e.which);
           if (word.substring(0, t.length) == t) {
                $("#theWord").html("<span class='highlight'>" + t +"</span>"+ word.substring(t.length));               
            }
           else
           {
               t=t.substring(0,t.length - 1);               
           }
       }
   });