Event delegation

HTML

<!-- Learn about this code on MDN: https://developer.mozilla.org/en-US/docs/Web/Events/focus -->

<form id="form">
  <input type="text" placeholder="text input">
  <input type="password" placeholder="password">
</form>

JavaScript

var eventName, useCapture;
if ("onfocusin" in document) {
	eventName = "focusin";
  useCapture = false;
} else {
	eventName = "focus";
  useCapture = true;
}

document.body.addEventListener(eventName, function( event ) {
    event.target.style.background = "pink";    
  }, useCapture);