StackOverflow : Precedence of nested events

http://stackoverflow.com/questions/35490587/precedence-of-nested-events/35494241

by Nicolas Escoffier

HTML

<input type="text" />

JavaScript

document.addEventListener('keypress', function(e){
  var key = String.fromCharCode(e.which),
      targetElt = e.target;
      
  if (key === 'a'){
    console.log('-- Action when "a" is pressed')
    if (targetElt.nodeName === 'INPUT') {
      console.log('-- Action when "a" is pressed and the focus is on an input');
    }
  } 
}, false);