I have this code :
<input id="inputBox" />
$('#inputBox').keypress(function(event) {
console.log($(this).val());
});
what I expect to it is, when I insert a value in the input box, have the print of it on the console. Instead, at first value, I get (an empty string), at second value, the first value, and so on…
Why? And how can I fix it? I also read the official document, but nothing about this behaviour!
The problem here is to with the points at which the different keyboard events are fired. To achieve what you want, use
keyupinstead.Updated fiddle