Paolo
Paolo

Reputation: 15847

Javascript keypress/down/up events firing order

Consider this simple code:

document.addEventListener( 'keypress', function() { console.log( 'press' ); } );
document.addEventListener( 'keydown',  function() { console.log( 'down' );  } );
document.addEventListener( 'keyup',    function() { console.log( 'up' );    } );

I tried it on both Safari 9 and FF 51 and the order the events fire is always:

down -> press -> up

This makes perfect sense (at least for me).

My question is:

Is this standard behaviour or some browsers (maybe older ones like IE8) trigger key events in a different order?

More specifically I'm interested to know if some browsers fires press before down.

Upvotes: 0

Views: 263

Answers (1)

Abhinav
Abhinav

Reputation: 1200

as long as order is concern, yes all browser will execute same order... IE8 will not support addListner event so no question for order there.. but IE9 and IE9+ will execute same order.

Upvotes: 1

Related Questions