1
votes

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)

1
Just look at the object's type property? jsfiddle.net/57amLho6Al.G.
@Al.G. Uh! looking through the properties at MDN iI missed the introductory paragraph :-). Please feel free to add this as an answer and I'd accept.tru7

1 Answers

1
votes

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>