jQuery Focusin Event

Beginner
5 min read
Updated: Nov 2026
3 examples
Form Events

Definition

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.

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);
CallWhat it does
Parent elementContainer that listens (form, div, paragraph)
Selector filter"input", "textarea", etc. for delegation
handlerfunction(event) — runs on gain of focus
eventDataExtra data available as event.data

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Bind with .on("focusin", handler) on a parent, or .on("focusin", "input", handler) for delegation.
Step 2Optionally pass eventData: .on("focusin", data, handler).
Step 3Inside the handler, use event.target or $(this) (delegated) for the focused control.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

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.

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.

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.

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() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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