Skip to content

TIL: Capture keydown events on DIV elements

How to capture keydown/keypress events on HTML elements that aren't inputs

1 min read

Just set the tabindex attribute, then you'll be able to listen to keydown --- or keyup, keypress --- events like this:

HTML
<div tabindex="1" @keydown.esc="doSomething()">
I can emit keydown events now!
</div>

More notes connected by topic, not algorithmic noise.