Skip to main content
edited title
Link

How to style every individual word with different color using javascript?

Source Link

How to style every individual word with different color using javascript?

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