jQuery .focusin() Method

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

Definition

.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").

Syntax

Start with these common calls. Keep them short and readable.

jQuery
// 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);
CallWhat it does
handlerfunction(event) — runs on gain of focus (self or child)
eventDataExtra data available as event.data
No-arg callFires focusin on each matched element
Parent targetForm, paragraph, or wrapper around inputs

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

Parameters

ParameterDescription
Step 1Bind with .focusin(handler) (legacy) or .on("focusin", handler) (preferred).
Step 2Optionally pass eventData: .focusin(data, handler) → .on("focusin", data, handler).
Step 3Trigger with no-arg .focusin() (legacy) or .trigger("focusin") (preferred).

Return Value

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

jQuery Examples

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.

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.

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.

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 →

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