My code is converting entire input to single color, but not individual colors to individual words. Here is my fiddle where only red gets applied to entire input. Test Input: hi hello etc. When I clear the input field, the last color is applied to the first word but not the red color. The function is
function func(e){ var content = text.innerHTML; if( e.keyCode === 32){ text.style.color = colors[i++]; } } Here is the fiddle : Fiddle Link