.focus() is jQuery’s legacy shorthand for binding or triggering the focus event when an element gains keyboard or mouse focus. Binding is deprecated since 3.3; modern code uses .on("focus") / .trigger("focus").
Remember
// Legacy (still works; bind form deprecated since 3.3)
$("#login").focus(function () {
// field gained focus
});
// Modern replacements
$("#login").on("focus", handler); // bind
$("#login").trigger("focus"); // fire + move focus
// Auto-focus on load (legacy)
$(function () { $("#login").focus(); });
Trigger with no-arg .focus() (legacy) or .trigger("focus") (preferred).
Only trigger on visible elements — hidden targets can error in IE.
For parent forms / dynamic fields, use focusin — .focus() has no delegation.
Piece
Required?
Role
handler
For bind form
function(event) — runs when focus is gained
eventData
Optional (1.4.3+)
Extra data available as event.data
No-arg call
For trigger
Moves focus and runs bound handlers
Visibility
For trigger
Element must be visible (IE safety)
Pseudocode
Pseudocode
// Legacy
call element.focus(handler)
→ bind "focus" on element
call element.focus()
→ trigger "focus" on element
→ move keyboard focus (if visible)
// Modern (jQuery 1.7+)
call element.on("focus", handler)
when user clicks / tabs into element:
fire "focus" on element
call handler(event)
to migrate:
.focus(fn) → .on("focus", fn)
.focus(data, fn) → .on("focus", data, fn)
.focus() → .trigger("focus")
Both bind the same event — .on() is the recommended API for new code.
jQuery
$("#legacy").focus(function () {
$("#out").text("Legacy: .focus(fn) — deprecated since 3.3.");
});
$("#modern").on("focus", function () {
$("#out").text("Modern: .on('focus', fn) — use this for new code.");
});
Page loads → #login is focused
User can type immediately
Modern: $("#login").trigger("focus")
How It Works
Ready.$(function(){ … }) waits for the DOM.
Trigger. No-arg .focus() activates #login.
Type. The user can start typing without a click.
Migrate. Prefer .trigger("focus") on a visible field.
Edge Cases & Pitfalls
Watch for these when reading or migrating legacy .focus() code.
deprecated
Bind form deprecated since 3.3
Still works in jQuery 3.x, but new code should use .on("focus").
IE
Hidden elements can error
Do not call no-arg .focus() on a hidden field in IE. Show it first, or use .triggerHandler("focus").
bind vs trigger
.focus(fn) ≠ .focus()
With a function it binds; with no args it triggers. Always check the parentheses.
delegation
No built-in delegation
.focus(fn) cannot target future elements. Use $("#form").on("focus", "input", fn) or focusin.
Compatibility
Browser Support
The underlying focus event is a standard DOM event. The .focus() method is a jQuery API available since 1.0 (eventData since 1.4.3). Binding via .focus(handler) is deprecated since 3.3 but still functional in jQuery 3.x.
✓ Deprecated · jQuery 3.3
jQuery .focus()
Works in jQuery 1.x–3.x. Prefer .on('focus') / .trigger('focus') for new projects. Avoid triggering focus on hidden elements in IE.
100%With jQuery loaded
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.focus()Legacy API
Bottom line: Safe in legacy projects. Migrate bindings to .on('focus') and triggers to .trigger('focus') when you touch form scripts.
Analysis
Performance Notes
Approach
Cost
Best for
Direct .on("focus") on known fields
Cheap
Login, search, single inputs
Delegated focusin on a form
Cheap
Dynamic / many nested fields
Heavy work on every focus
Expensive
Avoid — keep handlers light
The shorthand and .on("focus") cost the same for a single bind. Prefer .on() for clarity and delegation. Keep the callback light.
Remember
Key Takeaways
Role: legacy bind/trigger when an element gains focus.
Migrate:.on("focus", fn) and .trigger("focus").
Two forms:.focus(fn) binds; .focus() triggers.
Visible only: never trigger focus on hidden IE targets.
One line:.focus() is deprecated sugar for .on("focus") / .trigger("focus") — migrate when you touch the file.
Frequently Asked Questions
The .focus() method has two roles. With a handler — .focus(handler) or .focus(eventData, handler) — it binds a function that runs when the matched element gains focus. With no arguments — .focus() — it triggers the focus event, running bound handlers and moving keyboard focus. Binding has been part of jQuery since 1.0 and is deprecated since 3.3.
Yes. The binding signatures .focus(handler) and .focus(eventData, handler) are deprecated since jQuery 3.3. Use .on("focus", handler) instead. The no-argument .focus() trigger still works, but .trigger("focus") is clearer. Legacy code continues to run in jQuery 3.x.
.focus(handler) registers a callback and does not fire immediately. .focus() with no arguments triggers the focus event — the same as .trigger("focus"). Check whether parentheses contain a function before reading legacy code.
Replace .focus(fn) with .on("focus", fn). Replace .focus(data, fn) with .on("focus", data, fn). Replace no-arg .focus() with .trigger("focus"). Cleanup with .off("focus"). Under the hood, .focus(handler) already delegates to .on("focus").
Yes. jQuery 3.x keeps .focus() for backward compatibility. It still binds and triggers correctly. The docs mark binding as deprecated to steer new projects toward .on() and .trigger(). Prefer the modern API in the focus event tutorial.
No in Internet Explorer — triggering focus on a hidden element can throw. Only call no-arg .focus() or .trigger("focus") on visible elements. Use .triggerHandler("focus") if you need handlers without moving focus.