The focus event fires when an element gains focus — the user clicks into a field, tabs to it, or you call .trigger("focus"). Bind with .on("focus", handler) (jQuery 1.7+). Focus does not bubble; use focusin for parent-level handlers.
Remember
$("#target").on("focus", function () {
// field gained focus
});
$("#target").trigger("focus"); // move focus + run handlers
$("#target").triggerHandler("focus"); // handlers only (no move)
// focus does NOT bubble → for forms use focusin
$("#form").on("focusin", "input", handler);
Trigger with .trigger("focus") — only on visible elements.
Use .triggerHandler("focus") when you want handlers without moving focus.
For dynamic forms, prefer delegated focusin on a parent.
Piece
Required?
Role
handler
For bind
function(event) — runs when focus is gained
eventData
Optional
Extra data available as event.data
Visibility
For trigger
Hidden elements can error in IE
Typical targets
Yes
Inputs, textareas, selects, links, tabindex elements
Pseudocode
Pseudocode
call element.on("focus", handler)
→ store handler on element
when user clicks / tabs into element:
fire "focus" on element
call handler(event)
call element.trigger("focus")
if element is hidden (IE):
error — do not trigger
else:
move keyboard focus
call bound handlers
call element.triggerHandler("focus")
→ run handlers only (no focus move)
for parent form with many inputs:
use .on("focusin", "input", handler)
// focus itself does not bubble
Reference
Cheat Sheet
Keep these facts handy while wiring form focus UX.
Topic
Detail
Bind
$("#el").on("focus", handler)
Trigger
$("#el").trigger("focus")
Handlers only
$("#el").triggerHandler("focus")
Unbind
$("#el").off("focus" [, handler])
Bubbles?
No — use focusin for parents
vs blur
Gain focus vs lose focus
vs focusin
Same idea, but focusin bubbles
Since
.on("focus") 1.7 · .trigger("focus") 1.0
Legacy shorthand
.focus() ⚠ deprecated for binding since 3.3
Try it
Live Preview
Click into the field, tab to it, or run an action to see .on("focus") and .trigger("focus") in action.
You can also click or tab into the demo input below.
Result
Ready — click the input or pick an action.
Code
jQuery Examples
Short, copy-ready snippets based on the official jQuery API demos. Open Try It Yourself for a live editor.
Example 1 — Basic .on("focus")
Official pattern: run a handler when #target gains focus.
jQuery
$("#target").on("focus", function () {
$("#out").text("Handler for focus called.");
});
Tab into first → "Active field: first"
Tab into last → "Active field: last"
New fields added later still work
How It Works
Parent bind. The handler lives on #signup-form.
Bubble.focusin bubbles from the input to the form.
Filter. The "input" selector matches the focused control.
Dynamic. Fields added later are covered automatically.
Edge Cases & Pitfalls
Check these before relying on focus handlers in real forms.
bubble
focus does not bubble
A parent .on("focus", fn) will not see child focus. Use focusin or delegated .on("focus", "input", fn).
IE
Hidden elements error in IE
Do not call .trigger("focus") on a hidden field. Show it first, or use .triggerHandler("focus").
shorthand
.focus(handler) is deprecated
Prefer .on("focus", handler). The shorthand bind form is deprecated since jQuery 3.3.
pair
Pair with blur
Show hints on focus and clean up on blur so helpers do not stick around after the user leaves.
Compatibility
Browser Support
The focus event is a standard DOM event. Bind with .on("focus") since jQuery 1.7; .trigger("focus") has existed since 1.0. As of jQuery 3.7.0, IE uses focusin as the native backing event for focus to avoid async quirks.
✓ jQuery 1.7+
jQuery focus event
Supported in all browsers jQuery targets. Prefer .on('focus') / .trigger('focus'). For parent forms, use focusin. Native equivalent: element.addEventListener('focus', fn).
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
focusExcellent
Bottom line: Safe for modern and legacy jQuery projects. Avoid triggering focus on hidden elements in IE, and use focusin when you need bubbling.
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
Focus fires often while users tab through a form. Keep callbacks small — toggle a hint, set a class, or update a short label.
Remember
Key Takeaways
Role: react when an element gains keyboard/mouse focus.
API:.on("focus", fn) and .trigger("focus").
No bubble: use focusin for parent/form handlers.
Visible only: never .trigger("focus") on hidden IE targets.
One line: use .on("focus") for single fields, focusin for forms, and .trigger("focus") only on visible elements.
Frequently Asked Questions
The focus event fires when an element gains focus — the user clicks into a field, tabs to it, or you call .trigger("focus"). Bind handlers with .on("focus", handler) since jQuery 1.7. It applies to form controls, links, and elements with a tabindex.
They are opposites. focus fires when an element receives focus; blur fires when it loses focus. Pair them for UX: .on("focus") to show helper text, .on("blur") to validate or hide hints.
No. Native focus does not bubble. For one handler on a parent form, use focusin (it bubbles). Since 1.4.2, jQuery maps delegated .on("focus", selector, fn) to focusin behind the scenes.
Call $("#login").trigger("focus") on a visible element. It runs bound handlers and moves keyboard focus. Use .triggerHandler("focus") to run handlers without moving focus. Avoid .trigger("focus") on hidden elements in Internet Explorer — it causes an error.
Inside $(function(){ ... }), call $("#login").trigger("focus") after the DOM is ready. This matches the official jQuery API example and is similar to the HTML autofocus attribute. Ensure the element is visible first.
Prefer .on("focus", handler) and .trigger("focus"). The .focus() shorthand binding form is deprecated since jQuery 3.3. See the .focus() method tutorial for migration details.