tru7
tru7

Reputation: 7212

KeyboardEvent object, determine if it's keyUp or down

Having a single KeyboardEvent object, is it possible to know if it corresponds to a KeyDown or KeyUp event? (I know I can keep somewhere the event KeyUp or Down that triggers it but I am looking for a way to assess that independently of the trigger)

Upvotes: 1

Views: 160

Answers (1)

Al.G.
Al.G.

Reputation: 4387

Look at the type property on the object you've got:

let b = document.getElementById('b');
b.onkeydown = b.onkeyup = function(e){ console.log(e.type); };
<button id="b">Button</button>

Upvotes: 1

Related Questions