VOOZH about

URL: https://www.geeksforgeeks.org/jquery/how-to-set-different-color-for-each-letter-in-a-text-field-using-jquery/

⇱ How to set different color for each letter in a text field using jQuery ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to set different color for each letter in a text field using jQuery ?

Last Updated : 23 Jul, 2025

In this article, we will find how to set a different color for each letter in a text field using jQuery?

Approach:

To do this we will have to change the color of text whenever the user enters a letter using the keyboard. For this, we will use onkeydown event that triggers whenever the user presses a key on the keyboard.

Syntax:

object.onkeydown = function(){Script}

Example: Let us look at an example to find how to set a different color for each letter in a text field using jQuery onkeydown event.

Output:

👁 Image
Change color of text using keydown event
Comment

Explore