jQuery .focusin() Method

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

What Is .focusin()?

.focusin() is jQuery’s legacy shorthand for binding or triggering the bubbling focusin event — when an element or a descendant gains focus. Binding is deprecated since 3.3; modern code uses .on("focusin") / .trigger("focusin").

Remember
// Legacy (still works; bind form deprecated since 3.3)
$("p").focusin(function () {
  // this <p> or a nested input gained focus
});

// Modern replacements
$("p").on("focusin", handler);     // bind
$("p").trigger("focusin");         // fire handlers

// Better for dynamic forms (delegation)
$("#form").on("focusin", "input", handler);
NeedUse
New code (bind).on("focusin", fn)
New code (trigger).trigger("focusin")
Legacy bind.focusin(fn) ⚠ deprecated 3.3
Legacy trigger.focusin() (prefer .trigger)
Delegation.on("focusin", "input", fn) — not via .focusin()

How to Use .focusin()

Recognize the legacy API in old code, then migrate to .on() / .trigger().

  1. Bind with .focusin(handler) (legacy) or .on("focusin", handler) (preferred).
  2. Optionally pass eventData: .focusin(data, handler) → .on("focusin", data, handler).
  3. Trigger with no-arg .focusin() (legacy) or .trigger("focusin") (preferred).
  4. Bind on a parent to catch nested input focus (bubbling).
  5. For dynamic fields, use delegated .on("focusin", selector, fn) — not .focusin().
PieceRequired?Role
handlerFor bind formfunction(event) — runs on gain of focus (self or child)
eventDataOptional (1.4.3+)Extra data available as event.data
No-arg callFor triggerFires focusin on each matched element
Parent targetTypicalForm, paragraph, or wrapper around inputs

Pseudocode

Pseudocode
// Legacy
call parent.focusin(handler)
    → bind "focusin" on parent

when nested input gains focus:
    fire "focusin" on input
    event bubbles to parent
    call handler(event)

call parent.focusin()
    → trigger "focusin" on parent (handlers only)

// Modern
call parent.on("focusin", handler)
// or with delegation for dynamic fields:
call parent.on("focusin", "input", handler)

to migrate:
    .focusin(fn)      → .on("focusin", fn)
    .focusin(data, fn) → .on("focusin", data, fn)
    .focusin()        → .trigger("focusin")

Cheat Sheet

Quick map from the shorthand to modern APIs.

TopicDetail
Legacy bind$("p").focusin(handler) ⚠ deprecated 3.3
Modern bind$("p").on("focusin", handler)
Legacy trigger$("p").focusin()
Modern trigger$("p").trigger("focusin")
Unbind$("p").off("focusin" [, handler])
Since / status1.0 · eventData 1.4.3 · bind deprecated 3.3
Bubbles?Yes — unlike .focus() / focus
vs .focus().focusin() catches nested focus; .focus() does not
DelegationNot via .focusin() — use .on("focusin", "input", fn)

Live Preview

Focus nested fields. The form uses legacy .focusin(handler) (still available in jQuery 3.x).

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. Prefer .on("focusin") for new projects; these demos show the legacy API you will still meet in older code.

Example 1 — Basic .focusin(handler) on a Parent

Bind on a paragraph so nested inputs trigger the handler.

jQuery
$("p").focusin(function () {
  var label = $(this).find("label").text() || "field";
  $("#out").text("focusin via .focusin(fn) — " + label.trim());
});
Try It Yourself

How It Works

  1. Bind. .focusin(fn) registers the callback on each <p>.
  2. Focus. Entering a nested input fires focusin.
  3. Bubble. The event reaches the parent paragraph.
  4. Prefer. New code should use .on("focusin", fn).

Example 2 — .focusin(eventData, handler)

Pass metadata (since 1.4.3). Modern form: .on("focusin", data, fn).

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

How It Works

  1. Data. The object becomes event.data.
  2. Bubble. Nested input focus reaches #profile.
  3. Target. event.target is the focused control.
  4. Migrate. Replace with .on("focusin", { form: "profile" }, fn).

Example 3 — No-Arg .focusin() Trigger

Fire focusin from a button — runs bound handlers (does not move the caret).

jQuery
$("#box").focusin(function () {
  $("#out").text("focusin handler fired on #box.");
});

$("#fire").on("click", function () {
  $("#box").focusin(); // prefer .trigger("focusin")
});
Try It Yourself

How It Works

  1. Bind. The handler is registered on #box.
  2. Click. No-arg .focusin() triggers the event.
  3. Handlers. Bound focusin callbacks run immediately.
  4. Caret. To move focus, use .trigger("focus") on an input.

Example 4 — Migrate to .on("focusin")

Both bind the same event — .on() is the recommended API for new code.

jQuery
$("#legacy").focusin(function () {
  $("#out").text("Legacy: .focusin(fn) — deprecated since 3.3.");
});

$("#modern").on("focusin", function () {
  $("#out").text("Modern: .on('focusin', fn) — use this for new code.");
});
Try It Yourself

How It Works

  1. Legacy. .focusin(fn) internally calls .on("focusin", fn).
  2. Modern. Bind directly with .on().
  3. Same event. Bubbling focusin behavior is unchanged.
  4. Bonus. Only .on() supports selector delegation.

Example 5 — .focusin() vs .focus() on a Parent

Prove that parent .focus() misses nested inputs while .focusin() catches them.

jQuery
var log = [];
$("#wrapper").focus(function () {
  log.push("focus on wrapper (will NOT run)");
});
$("#wrapper").focusin(function () {
  log.push("focusin on wrapper (runs)");
  $("#out").text(log.join(" | "));
});
Try It Yourself

How It Works

  1. .focus. Non-bubbling — parent handler misses child focus.
  2. .focusin. Bubbling — parent handler runs.
  3. Log. Only the focusin message appears.
  4. Rule. Use focusin (or .on("focusin")) for parents.

Edge Cases & Pitfalls

Watch for these when reading or migrating legacy .focusin() code.

deprecated

Bind form deprecated since 3.3

Still works in jQuery 3.x, but new code should use .on("focusin").

delegation

No built-in delegation

.focusin(fn) cannot target future elements. Use $("#form").on("focusin", "input", fn).

trigger

No-arg .focusin() ≠ move caret

It runs handlers. To move keyboard focus, call .trigger("focus") on a visible input.

bind vs trigger

.focusin(fn) ≠ .focusin()

With a function it binds; with no args it triggers. Always check the parentheses.

Browser Support

The underlying focusin event is a standard DOM event with bubbling. The .focusin() method is a jQuery API available since 1.0 (eventData since 1.4.3). Binding via .focusin(handler) is deprecated since 3.3 but still functional in jQuery 3.x.

✓ Deprecated · jQuery 3.3

jQuery .focusin()

Works in jQuery 1.x–3.x. Prefer .on('focusin') / .trigger('focusin') for new projects. Use parents to catch nested focus.

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() Legacy API

Bottom line: Safe in legacy projects. Migrate bindings to .on('focusin') and triggers to .trigger('focusin') when you touch form scripts.

Performance Notes

ApproachCostBest for
One .on("focusin") on a formCheapMany nested fields
Delegated .on("focusin", "input", fn)CheapDynamic / AJAX fields
Heavy work on every focusinExpensiveAvoid — keep handlers light

The shorthand and .on("focusin") cost the same for a single bind. Prefer .on() for clarity and delegation. Keep the callback light.

Key Takeaways

  • Role: legacy bind/trigger for bubbling focusin.
  • Migrate: .on("focusin", fn) and .trigger("focusin").
  • Parent bind: catches nested input focus (unlike .focus()).
  • Delegation: only available via .on("focusin", selector, fn).

One line: .focusin() is deprecated sugar for .on("focusin") / .trigger("focusin") — migrate when you touch the file.

Frequently Asked Questions

The .focusin() method has two roles. With a handler — .focusin(handler) or .focusin(eventData, handler) — it binds a function that runs when the matched element or any descendant gains focus (bubbles). With no arguments — .focusin() — it triggers the focusin event on each matched element. Binding has been part of jQuery since 1.0 and is deprecated since 3.3.
Yes. The binding signatures .focusin(handler) and .focusin(eventData, handler) are deprecated since jQuery 3.3. Use .on("focusin", handler) instead. The no-argument .focusin() trigger still works, but .trigger("focusin") is clearer. Legacy code continues to run in jQuery 3.x.
.focusin(handler) registers a callback and does not fire immediately. .focusin() with no arguments triggers the focusin event — the same as .trigger("focusin"). Check whether parentheses contain a function before reading legacy code.
Replace .focusin(fn) with .on("focusin", fn). Replace .focusin(data, fn) with .on("focusin", data, fn). Replace no-arg .focusin() with .trigger("focusin"). Cleanup with .off("focusin"). Under the hood, .focusin(handler) already delegates to .on("focusin").
.focus() binds or triggers the non-bubbling focus event on the matched element. .focusin() binds or triggers the bubbling focusin event — better for parent containers that detect focus on nested inputs. To move keyboard focus, use .trigger("focus") on the target input.
No. Direct .focusin(fn) only binds to elements that already match. For dynamic fields, use .on("focusin", "input", fn) on a parent. That is one reason to prefer .on() over the shorthand.

Next: blur event

Learn how to react when an element loses focus with .on("blur").

blur event 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