0

I need to create an input type having text, of different color .

Ex. first 5 characters in color black and the rest in red

Is this possible with jquery or something ?

By input i mean

<input type="text" value="blackreddddd" />

Thank you.

Jot Dhaliwal
  • 1,470
  • 4
  • 26
  • 47
Mistraë
  • 338
  • 5
  • 21

1 Answers1

1

You can create a function which can accept no of characters and then replace the html with the same.

Example Fiddle

Code for the same:

var str = $('#test').html();

function color(noOfCharacters) {
    $('#test').html('<span style="color:red">' + str.substr(0, noOfCharacters) + '</span><span>' + str.substr(noOfCharacters, str.length) + '</span>');
}
color(4);
V31
  • 7,626
  • 3
  • 26
  • 44