jQuery Focusin Event

Beginner
7 min read
Updated: Oct 2026
5 examples
Live preview

What Is the focusin Event?

The focusin event fires when an element or any element inside it gains focus. Unlike focus, focusin bubbles — 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);
NeedUse
One handler for a form.on("focusin", "input", fn)
Single field only.on("focus", fn)
Lose focus (bubbling).on("focusout", …)
Trigger handlers.trigger("focusin")
Move keyboard focus.trigger("focus") on the input

How to Use focusin

Bind on a parent, filter with a selector, and react when any nested field gains focus.

  1. Bind with .on("focusin", handler) on a parent, or .on("focusin", "input", handler) for delegation.
  2. Optionally pass eventData: .on("focusin", data, handler).
  3. Inside the handler, use event.target or $(this) (delegated) for the focused control.
  4. Pair with focusout when you need enter and exit on the same parent.
  5. To move keyboard focus, call .trigger("focus") on the input — not only focusin.
PieceRequired?Role
Parent elementYesContainer that listens (form, div, paragraph)
Selector filterOptional"input", "textarea", etc. for delegation
handlerFor bindfunction(event) — runs on gain of focus
eventDataOptionalExtra 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")

Cheat Sheet

Keep these facts handy when wiring bubbling focus UX.

TopicDetail
Bind$("#form").on("focusin", "input", handler)
Trigger$("#el").trigger("focusin")
Unbind$("#form").off("focusin" [, handler])
Bubbles?Yes — unlike focus
vs focusSame idea; focusin bubbles to parents
vs focusoutGain 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

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.

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());
});
Try It Yourself

How It Works

  1. Bind. Each <p> listens for focusin.
  2. Focus. Entering a nested input fires focusin.
  3. Bubble. The event reaches the parent paragraph.
  4. Update. Status text shows which parent reacted.

Example 2 — Delegated focusin on a Form

One handler on the form tracks whichever input is active.

jQuery
$("#signup-form").on("focusin", "input", function () {
  $("#out").text("Active field: " + ($(this).attr("name") || "(unnamed)"));
});
Try It Yourself

How It Works

  1. Parent. The handler lives on #signup-form.
  2. Filter. "input" matches the focused control.
  3. this. In a delegated handler, $(this) is the input.
  4. 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(" | "));
});
Try It Yourself

How It Works

  1. focus. Does not bubble — parent handler misses child focus.
  2. focusin. Bubbles — parent handler runs.
  3. Log. Only the focusin message appears.
  4. Rule. Use focusin (or delegated focus) for parents.

Example 4 — eventData with Delegated focusin

Pass shared metadata into every delegated callback.

jQuery
$("#profile").on("focusin", "input", { form: "profile" }, function (event) {
  $("#out").text(
    "form=" + event.data.form + " | field=" + $(this).attr("name")
  );
});
Try It Yourself

How It Works

  1. Data. The object becomes event.data.
  2. Delegate. The selector still matches the focused input.
  3. Read. Combine event.data with $(this).attr("name").
  4. Reuse. One object serves every field in the form.

Example 5 — Dynamic Fields Keep Working

Add inputs after bind — the parent focusin handler still covers them.

jQuery
$("#signup-form").on("focusin", "input", function () {
  $("#out").text("Active: " + ($(this).attr("name") || "(unnamed)"));
});

$("#add").on("click", function () {
  $("#extra").append('

'); });
Try It Yourself

How It Works

  1. Bind once. The handler stays on the form.
  2. Add. New inputs are appended under the same parent.
  3. Bubble. Their focusin still reaches the form.
  4. 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.

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
focusin Excellent

Bottom line: Safe for modern and legacy jQuery projects. Use focusin whenever a parent must react to nested focus — including dynamic fields.

Performance Notes

ApproachCostBest for
One delegated focusin on a formCheapMany / dynamic fields
Direct .on("focus") per fieldCheapFew static inputs
Heavy work on every focusinExpensiveAvoid — keep handlers light

Delegation usually wins for forms: one listener instead of N. Keep the callback small — update a label or toggle a class.

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.

Next: .focus() method

Learn the deprecated shorthand for bind/trigger focus — and how to migrate it.

.focus() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful