JQuery how to add the last typed character

I made this code:

$('.change').keydown(function(){ var value = $(this).val(); var id = $(this).attr('id'); $('.'+id).text(value); }); 

It works great with 1 flaw. When I write something, it does not update my last inserted character. Therefore, when I start typing in โ€œTest caseโ€, the div is populated in order, although it stops at โ€œTest casโ€. As you can see, I am missing the last character.

How can I do this to add the last character?

+4
source share
2 answers

you should use the event keyword, not keydown.

Then it should work.

+12
source

Change the event to keyup , this will work ...

 $('.change').keyup(function(){ var value = $(this).val(); var id = $(this).attr('id'); $('.'+id).text(value); }); 

Fiddle: http://jsfiddle.net/RYh7U/84/

+1
source

All Articles