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.
Remember
// 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);
Inside the handler, use event.target or $(this) (delegated) for the focused control.
Pair with focusout when you need enter and exit on the same parent.
To move keyboard focus, call .trigger("focus") on the input — not only focusin.
Piece
Required?
Role
Parent element
Yes
Container that listens (form, div, paragraph)
Selector filter
Optional
"input", "textarea", etc. for delegation
handler
For bind
function(event) — runs on gain of focus
eventData
Optional
Extra data available as event.data
Pseudocode
Pseudocode
call parent.on("focusin", "input", handler)
→ store delegated handler on parent
when user focuses a nested input:
fire "focus" on the input (does not bubble)
fire "focusin" on the input
focusin bubbles → reaches parent
if target matches "input":
call handler(event)
this → the input (delegated)
call parent.on("focus", handler)
→ never runs for nested input focus
(focus does not bubble)
to migrate shorthand:
.focusin(fn) → .on("focusin", fn)
.focusin() → .trigger("focusin")
Reference
Cheat Sheet
Keep these facts handy when wiring bubbling focus UX.
Topic
Detail
Bind
$("#form").on("focusin", "input", handler)
Trigger
$("#el").trigger("focusin")
Unbind
$("#form").off("focusin" [, handler])
Bubbles?
Yes — unlike focus
vs focus
Same idea; focusin bubbles to parents
vs focusout
Gain vs lose; both bubble
Since
.on("focusin") 1.7 · .trigger("focusin") 1.0
Legacy shorthand
.focusin() ⚠ deprecated for binding since 3.3
Delegated focus
.on("focus", "input", fn) uses focusin under the hood
Try it
Live Preview
Tab into nested fields. The form listens with .on("focusin", "input", …) — one handler covers every input.
You can also click or tab into the demo fields below.
Result
Ready — focus a field or pick an action.
Code
jQuery Examples
Short, copy-ready snippets based on the official jQuery API idea — listen on a parent when nested controls gain focus.
Example 1 — focusin on a Parent
Official idea: bind on a parent so nested inputs trigger the handler.
jQuery
$("p").on("focusin", function () {
var label = $(this).find("label").text() || "field";
$("#out").text("focusin on parent <p> — nested " + label.trim());
});
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.
Reuse. One binding covers every matching field.
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(" | "));
});
Click Add → new input appears
Focus new field → "Active: extra"
No re-bind needed
How It Works
Bind once. The handler stays on the form.
Add. New inputs are appended under the same parent.
Bubble. Their focusin still reaches the form.
Match. The "input" filter includes the new fields.
Edge Cases & Pitfalls
Check these before relying on parent-level focus handlers.
focus
Parent focus will miss children
focus does not bubble. Use focusin (or delegated .on("focus", "input", fn)).
trigger
.trigger("focusin") ≠ move focus
It runs handlers. To move the caret, call .trigger("focus") on the visible input.
pair
Pair with focusout
Show hints on focusin and clear them on focusout so helpers do not stick around.
shorthand
.focusin(handler) is deprecated
Prefer .on("focusin", handler). The shorthand bind form is deprecated since jQuery 3.3.
Compatibility
Browser Support
The focusin event is a standard DOM event with bubbling. Bind with .on("focusin") since jQuery 1.7; .trigger("focusin") has existed since 1.0. jQuery has long used focusin for delegated focus (since 1.4.2).
✓ jQuery 1.7+
jQuery focusin event
Supported in all browsers jQuery targets. Prefer .on('focusin') for parent forms. Pair with focusout. Native equivalent: element.addEventListener('focusin', fn).
100%With jQuery loaded
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
focusinExcellent
Bottom line: Safe for modern and legacy jQuery projects. Use focusin whenever a parent must react to nested focus — including dynamic fields.
Analysis
Performance Notes
Approach
Cost
Best for
One delegated focusin on a form
Cheap
Many / dynamic fields
Direct .on("focus") per field
Cheap
Few static inputs
Heavy work on every focusin
Expensive
Avoid — keep handlers light
Delegation usually wins for forms: one listener instead of N. Keep the callback small — update a label or toggle a class.
Remember
Key Takeaways
Role: bubbling focus — parents can listen for nested focus.
API:.on("focusin", "input", fn) on the form.
vs focus: same idea, but focus does not bubble.
Pair: use focusout for the leave side of the same container.
One line: use focusin when a parent form must react to nested focus — including fields added later.
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.