skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. According to the W3C

    https://w3c.github.io/uievents/#events-keyboard-event-order

    the order is keydown, beforeinput, input, keyup.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search