Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery how to add last typed character

I made this code:

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

    $('.'+id).text(value);
});

It is working fine with 1 flaw. When i type something it doesn't update my last inserted character. So when i start typing "Test case" the div is filled alright although it stops with "Test cas". As you can see i am missing the last character.

How can i make this so that the last character is added?

like image 513
Augus Avatar asked Feb 15 '13 09:02

Augus


2 Answers

you should use the event keyup and not keydown.

Then it should work.

like image 160
Charles Avatar answered Sep 30 '22 02:09

Charles


Change the event to keyup it will work...

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

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

like image 44
Pandian Avatar answered Sep 30 '22 04:09

Pandian