JSFiddle - React, Tailwind, and code Playground

HTML

<div class="highlight">
      <input type="text" name="" value="" id="text">
    </div>

JavaScript

var text = document.getElementById('text');
        text.addEventListener("keyup", function(event){
          func(event)});
        var colors = ["red","green","blue","darkpink"];
        var i = 0;
        function func(e){
          var content = text.innerHTML;
          if(e.keyCode === 32){
            text.style.color = colors[i++];
          }
        }