The focusin event fires when an element or any element inside it gains focus. Unlike focus, focusinbubbles — so one handler on a parent form can cover every nested input, including fields added later.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
// Parent form — one handler for all inputs
$("#form").on("focusin", "input", function () {
// a nested input gained focus
});
// focus does NOT bubble; focusin does
$("#wrapper").on("focus", fn); // misses child focus
$("#wrapper").on("focusin", fn); // runs for child focus
// Pair with focusout for enter/exit
$("#form").on("focusout", "input", handler);
Call
What it does
Parent element
Container that listens (form, div, paragraph)
Selector filter
"input", "textarea", etc. for delegation
handler
function(event) — runs on gain of focus
eventData
Extra data available as event.data
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Bind with .on("focusin", handler) on a parent, or .on("focusin", "input", handler) for delegation.
Tab into first → "Active field: first"
Tab into email → "Active field: email"
How It Works
Parent. The handler lives on #signup-form.
Filter."input" matches the focused control.
this. In a delegated handler, $(this) is the input.
Example 3 — focus vs focusin on a Parent
Prove that parent focus stays silent while focusin runs.
jQuery
var log = [];
$("#wrapper").on("focus", function () {
log.push("focus on wrapper (will NOT run)");
});
$("#wrapper").on("focusin", function () {
log.push("focusin on wrapper (runs)");
$("#out").text(log.join(" | "));
});
Focus nested input
→ only "focusin on wrapper (runs)"
focus handler on #wrapper never fires
How It Works
focus. Does not bubble — parent handler misses child focus.
focusin. Bubbles — parent handler runs.
Log. Only the focusin message appears.
Frequently Asked Questions
The focusin event fires when an element gains focus, or when any element inside it gains focus. Unlike focus, focusin bubbles up the DOM — so you can bind one handler on a parent form and react when the user enters any nested input. Bind with .on("focusin", handler) since jQuery 1.7.
Both relate to gaining focus. focus fires only on the element that received focus and does not bubble. focusin fires on that element and bubbles to ancestors — ideal for event delegation on forms. Use focus for single-field handlers; use focusin when one parent handler should cover all inputs.
Yes. Native focusin bubbles from the focused element up through parents. That is why .on("focusin", "input", fn) on a form works. Since 1.4.2, jQuery also maps delegated .on("focus", "input", fn) to focusin internally.
They are opposites and both bubble. focusin fires when an element or its descendant gains focus. focusout fires when an element or its descendant loses focus. Pair them on a parent container for enter/exit tracking across dynamic forms.
Call .trigger("focusin") to run bound focusin handlers. To actually move keyboard focus, use .trigger("focus") on the target input — that fires both focus and focusin in the browser. Use .triggerHandler("focusin") to run handlers without side effects.
Prefer .on("focusin", handler) and .trigger("focusin"). The .focusin() shorthand binding form is deprecated since jQuery 3.3. See the .focusin() method tutorial for migration details.