
Gabriel F. answered 10/31/19
Full stack Javascript Engineer
Hi there. The keypress event is fired before the character is added to the element so you end up having a "delay by one" on your results. For instance:
You typed:
"abcd"
The resulting string would be "abc" because when you typed "b" the current value in the element is "a", then when you type "c" the current value in the element is "b", and so on.
Why not use the keyup event instead?