0

I've seen folks alternate colors of characters inside a single element by dynamically wrapping each in a span and targeting them individually, but I want to alternate the color of each character in an input field ( say for example alternate between red, green, blue ) ...is possible? I'm stumped...

Nick Briz
  • 1,917
  • 3
  • 20
  • 34

1 Answers1

1

It might be possible to simulate it using DIV with contentEditable attribute set to true and styled as an input box.

At the very basic, when you type into it, you can handle events such as "onkeydown" and surround character with a SPAN of a given color before adding it to the DIV.

This way you can get real- time coloring of characters in the "input" field as you type.

It grows more complicated if you have to handle paste/delete, but that's the idea.

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136