Listen on the form. One handler covers many controls.
Pass true as the third argument. Capture phase runs before the target (MDN).
Read event.target. The actual focused control inside the form.
Or use focusin. Bubbling alternative for the same delegation pattern.
Compatibility
Browser Support
Elementfocus is Baseline Widely available (MDN: since July 2015). Safe to use in modern and older evergreen browsers.
✓ Baseline · Widely available
focus
Fires when an element has received focus — FocusEvent, does not bubble.
99%Widely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
focusExcellent
Bottom line: Listen on the target, or use capture/focusin for parents. Pair with blur. Not cancelable.
Frequently Asked Questions
It fires when an element has received focus — for example when a user tabs to an input or clicks into it (MDN). The opposite event is blur, which fires when focus is lost.
No. MDN marks Element focus as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
No. focus does not bubble. The related focusin event that follows does bubble. For event delegation use focusin, or listen for focus in the capture phase (addEventListener(..., true)) (MDN).
A FocusEvent (inherits from UIEvent and Event). relatedTarget is the element that is losing focus, if any.
No. The focus event is not cancelable (MDN). You cannot stop an element from receiving focus by calling preventDefault() on focus.
Use focusin when you want a single listener on a parent (form, dialog, page) to react to focus on descendants, because focusin bubbles.