The focusin event fires when an element gains focus — or when any element inside it gains focus. Unlike focus, it bubbles up the DOM, so one handler on a parent form can react to every nested input. This tutorial covers .on("focusin"), eventData, delegation, comparison with focus and focusout, and the official jQuery paragraph demo.
01
.on()
Bind handler
02
Bubbles
Parent forms
03
Delegate
Dynamic inputs
04
vs focus
No bubble
05
focusout
Exit pair
06
Since 1.7
Modern API
Fundamentals
Introduction
Large forms with dozens of inputs are hard to manage if you bind .on("focus", fn) on every field individually. The focusin event solves this: it fires when an element gains focus or when any descendant gains focus, and it bubbles up to parent nodes.
The official jQuery API recommends pairing focusin with focusout for enter/exit tracking on containers. Bind with .on("focusin") since 1.7. jQuery also uses focusin internally when you delegate .on("focus", "input", fn) since 1.4.2.
Concept
Understanding the focusin Event
The focusin event is sent to an element when it gains focus, or when any element inside of it gains focus. This is distinct from the focus event: focus fires only on the focused element and does not bubble; focusin bubbles so parent containers can listen once for all nested fields.
When a user tabs into an input inside a <form>, the browser fires focus on the input and focusin on the input, the form, and every ancestor up to the document. jQuery’s .on("focusin", "input", fn) on the form catches every current and future input without rebinding.
💡
Beginner Tip
Pair focusin with focusout on the same parent: highlight the active field on .on("focusin", "input", fn), clear styling on .on("focusout", "input", fn). To actually move keyboard focus programmatically, use .trigger("focus") on the target input — that fires both focus and focusin in the browser.
Foundation
📝 Syntax
The modern jQuery API for the focusin event has two main forms — binding a handler and triggering the event:
$( "#form" ).on( "focusin", "input", function( event ) {
// jQuery maps focus to focusin for delegation since 1.4.2
} );
Native focus does not bubble. jQuery’s delegated .on("focus", "input", fn) works because jQuery maps it to the bubbling focusin event internally since 1.4.2. Binding .on("focusin", ...) directly makes the bubbling behavior explicit in your code.
3. Trigger the event — .trigger("focusin") (since 1.0)
jQuery
.trigger( "focusin" )
Runs bound focusin handlers on the matched element.
To move keyboard focus, use .trigger("focus") — the browser fires both focus and focusin.
Use .triggerHandler("focusin") to run handlers without bubbling side effects.
.on() and .trigger() return the original jQuery object for chaining.
Handler return values are ignored unless you use return false (equivalent to preventDefault() + stopPropagation()).
Cheat Sheet
⚡ Quick Reference
Goal
Code
Bind focusin on parent
$("#form").on("focusin", fn)
Delegated focusin on inputs
$("#form").on("focusin", "input", fn)
Move keyboard focus
$("#login").trigger("focus")
Run focusin handlers only
$("#form").trigger("focusin")
Run handlers without bubbling
$("#form").triggerHandler("focusin")
Remove focusin handlers
$("#form").off("focusin")
Non-bubbling alternative
$("#email").on("focus", fn)
Exit pair (bubbles)
$("#form").on("focusout", "input", fn)
Compare
📋 focusin vs focus vs focusout vs delegated focus
Four related APIs — pick bubbling vs non-bubbling and the right enter/exit pair for parent forms.
focusin
bubbles
Fires when element or descendant gains focus — one handler on a parent covers all nested inputs
focus
no bubble
Fires only on the focused element — best for single-field handlers on that input directly
focusout
bubbles
Opposite of focusin — fires when element or descendant loses focus; pair for enter/exit UX
.on("focus", sel)
delegate
jQuery maps delegated focus to focusin since 1.4.2 — same result, different event name
Hands-On
Examples Gallery
Example 1 is the official jQuery API paragraph demo. Examples 2–5 cover form delegation, focus vs focusin bubbling, eventData, and dynamic fields. Use the Try-it links to run each snippet in the browser.
📚 Binding & Triggering
Official jQuery demos for focusin handlers and programmatic triggers.
Example 1 — Official Demo: focusin on Paragraphs
Watch for focus inside paragraphs — show a “focusin fire” span when the user tabs into the nested input.
Tab into input inside first <p>
→ "focusin fire" span appears on that paragraph, fades over 1s
Handler runs on the <p> parent — focusin bubbled up from the input
How It Works
The handler binds on <p>, not the input. When the nested input gains focus, focusin bubbles to the paragraph. $(this) is the paragraph; .find("span") locates the hint inside it.
Example 2 — Delegated focusin on a Form
One handler on #signup-form highlights whichever input currently has focus.
Focus nested input inside #wrapper
→ only "focusin on wrapper" appears in #out
Direct .on("focus") on wrapper never fires for child input focus
How It Works
Native focus does not bubble — the wrapper’s focus handler only runs if the wrapper itself is focused. focusin bubbles from the input upward, so the wrapper handler runs every time.
Example 4 — Pass eventData to a Delegated Handler
Pass a theme object to every input’s focusin handler via one form binding.
Focus first name → border turns blue, #out shows name and theme
Focus email → same eventData.theme on every field
One { theme: "blue" } object shared across all inputs
How It Works
jQuery attaches { theme: "blue" } to event.data for every delegated focusin callback. The same pattern works with .on("focusin", eventData, handler) without a selector.
Example 5 — Dynamic Form: Add Fields, Keep One Handler
Inputs appended after page load still trigger the same focusin delegation — no rebinding needed.
Click "Add field" → new input appended
Tab into new input → .active and #status update
Delegation on #dynamic-form covers future inputs automatically
How It Works
Event delegation listens on the form, not individual inputs. When AJAX or DOM manipulation adds new fields, the existing focusin binding still works — the main reason to choose focusin over binding focus on each input.
Applications
🚀 Common Use Cases
Parent form highlighting — one .on("focusin", "input", fn) on the form highlights whichever field is active.
Nested containers — official demo: bind on <p> to react when any child input gains focus.
Dynamic AJAX forms — fields added after load still trigger the same delegated focusin handler.
Wizard steps — track which section the user is editing via focusin on step containers.
Pair with focusout — enter/exit styling on the same parent without per-field bindings.
Accessibility audit — log focusin on document during keyboard navigation testing.
🧠 How the focusin Event Bubbles
1
Input gains focus
User clicks or tabs into a nested <input> inside a form.
input
2
focus fires (no bubble)
Browser sends focus directly to the input — handlers on ancestors do not receive it.
focus
3
focusin bubbles up
focusin fires on the input, then the form, then ancestors — jQuery delegated handlers run.
focusin
4
✎
Parent handler runs
Your form-level function executes — highlight active field, show section hint. $(this) is the matched input when using a selector filter.
Important
📝 Notes
Bind with .on("focusin", handler) since jQuery 1.7.
Trigger with .trigger("focusin") since jQuery 1.0 — runs handlers; use .trigger("focus") to move keyboard focus.
Native focusinbubbles — ideal for parent-level and delegated handlers.
Native focus does not bubble — bind directly on the input for single-field handlers.
jQuery maps delegated .on("focus", selector, fn) to focusin since 1.4.2.
Pair with focusout on the same parent for complete enter/exit tracking.
Use .triggerHandler("focusin") to run handlers without bubbling propagation.
Use .off("focusin") to remove handlers — avoid deprecated .unbind("focusin").
Compatibility
Browser Support
The focusin event is a standard DOM focus event supported in every browser jQuery targets. jQuery’s .on("focusin") (since 1.7) and .trigger("focusin") (since 1.0) work across jQuery 1.x, 2.x, and 3.x.
✓ jQuery 1.7+
jQuery focusin event
Supported in jQuery 1.x, 2.x, and 3.x across all modern browsers and IE with supported jQuery versions. Native equivalent: element.addEventListener('focusin', fn) — jQuery adds collection binding, eventData, delegation, and .trigger() in one chainable API.
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
focusinUniversal
Bottom line: Safe in any jQuery project. Use focusin for parent-form delegation. Pair with focusout. Use .trigger('focus') to move keyboard focus — not .trigger('focusin') alone.
Wrap Up
Conclusion
The jQuery focusin event is the bubbling counterpart to focus. Bind one handler on a parent form with .on("focusin", "input", fn), pass optional eventData, and pair with focusout for complete enter/exit UX on dynamic forms.
Use focusin when you need delegation — the official paragraph demo shows it on <p> containers. For single-field handlers, focus on the input itself is simpler. Continue with the .focus() shorthand tutorial for legacy code, or the focus event tutorial for the non-bubbling API.
Bind .on("focusin", "input", fn) on parent forms for dynamic fields
Pair focusin and focusout on the same container
Use explicit focusin when bubbling semantics should be clear in code
Pass eventData to share config across all delegated inputs
Use .trigger("focus") to move keyboard focus — focusin handlers run automatically
❌ Don’t
Bind .on("focus", fn) on a parent expecting it to catch child input focus — it will not bubble
Confuse .trigger("focusin") with moving keyboard focus — use .trigger("focus")
Rebind handlers every time AJAX adds a field — delegation makes that unnecessary
Forget the focusout pair — users need exit styling too
Attach focusin on document in production without throttling — it fires on every focus change
Summary
Key Takeaways
Knowledge Unlocked
Six things to remember about the focusin event
Bubble, delegate, parent forms.
6
Core concepts
.on01
Bubbles
Up DOM
Core
form02
Delegate
One bind
Dynamic
↔03
vs focus
No bubble
Compare
out04
focusout
Exit pair
Pair
p05
<p> demo
Official
API
.off06
.off("focusin")
Unbind
Cleanup
❓ 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 tree — 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 an element 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, including fields added later.
Yes. Native focusin bubbles from the focused element up through parent nodes. That is why .on('focusin', 'input', fn) on a form works — the event reaches the form after the input receives focus. jQuery also maps delegated .on('focus', 'input', fn) to focusin internally since 1.4.2.
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 complete enter/exit tracking across dynamic forms.
Call .trigger('focusin') on an element since jQuery 1.0. Triggering focusin runs 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.
Use explicit focusin when you want bubbling semantics clear in your code, or when binding directly on a parent without a selector filter: $('#form').on('focusin', fn). Use .on('focus', 'input', fn) when you prefer the focus name — jQuery delegates via focusin under the hood. Both work for dynamic forms.
Did you know?
Because native focus does not bubble, jQuery’s event delegation maps .on("focus", selector, fn) to the bubbling focusin event under the hood since version 1.4.2. Binding .on("focusin", ...) directly makes the same behavior explicit — the approach used in the official jQuery API paragraph demo.