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)
@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>
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more
type
property? jsfiddle.net/57amLho6 – Al.G.