With jQuery, how do I capitalize the first letter of a text field while the user is still editing that field?

tresstylez picture tresstylez · Jan 7, 2010 · Viewed 190.6k times · Source

I'm looking for an example of how to capitalize the first letter of a string being entered into a text field. Normally, this is done on the entire field with a function, regex, OnBlur, OnChange, etc. I want to capitalize the first letter while the user is still typing.

For instance, if I'm typing the word "cat", the user should press 'c', and then by the time he presses 'a', the C should be capitalized in the field.

I think what I'm going for might be possible with keyup or keypress but I'm not sure where to start.

Anyone have an example for me?

Answer

NotMe picture NotMe · Jan 7, 2010

Just use CSS.

.myclass 
{
    text-transform:capitalize;
}