.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);
Call
What it does
handler
function(event) — runs on gain of focus (self or child)
eventData
Extra data available as event.data
No-arg call
Fires focusin on each matched element
Parent target
Form, paragraph, or wrapper around inputs
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Bind with .focusin(handler) (legacy) or .on("focusin", handler) (preferred).
Click #fire → no-arg .focusin() runs
Bound handler updates #out
Keyboard focus may stay on the button
How It Works
Bind. The handler is registered on #box.
Click. No-arg .focusin() triggers the event.
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.