An HTML textarea has two event listeners attached to it:
elTextarea.addEventListener('keydown', keyDown)
elTextarea.addEventListener('input', inputEvent)
Is it certain that the keyDown()
function will be called prior to inputEvent()
?
An HTML textarea has two event listeners attached to it:
elTextarea.addEventListener('keydown', keyDown)
elTextarea.addEventListener('input', inputEvent)
Is it certain that the keyDown()
function will be called prior to inputEvent()
?
2
Answers
I could not find a source that states this definitively.
But consider that the keyboard keyDown event is handled by the DOM KeyboardEvent
While the input event is handled by the HTMLElement TextAreaElement.
Thus I assume that there might be differences between different Browsers and the order in which they evaluate events on these Elements. And even if there was some standard for this somewhere assuming that browsers follow these standards is also not always a safe bet.
So I would suggest you try and find a way where you are not reliant on the order of these events firing since I do not see a technical reason why one should always be before the other on the side of the browser.
According to the W3C
the order is
keydown
,beforeinput
,input
,keyup
.