I use the 'keyup' event when I want to get the value of a text-input immediately after insertion.
Now I've seen in a CodeReview question the usage of an event 'input' for to accomplish the same.
The CodeReview question (5th line): https://codereview.stackexchange.com/questions/141937/registration-form-validation-in-jquery
I've tinkered a bit. Made this demo:
var box = document.querySelector('input');
box.addEventListener('keyup', function() {
console.log('keyup: %s', this.value);
});
box.addEventListener('input', function() {
console.log('input: %s', this.value);
});
/* RESULT
input: a
keyup: a
input: ab
keyup: ab
input: abc
keyup: abc
*/
<input type="text" />
As one can see: No difference!
Therefore my question:
Is there a difference between the usage of the keyup-event and the input-event (for reading the value of a text-input)?
And:
Are there cases in which one should prefer the one over the other?