jQuery Focusin Event

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Form events

What You’ll Learn

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

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.

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.

📝 Syntax

The modern jQuery API for the focusin event has two main forms — binding a handler and triggering the event:

1. Bind a handler — .on("focusin" [, eventData ], handler) (since 1.7)

jQuery
.on( "focusin" [, eventData ], handler )
  • eventData — optional object passed to the handler as event.data.
  • handler — function called each time focusin fires: function( event ) { ... }.

2. Event delegation — .on("focusin", selector, handler)

jQuery
$( "#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.

4. Unbind — .off("focusin" [, selector] [, handler])

jQuery
$( "#target" ).off( "focusin" );              // remove all focusin handlers
$( "#form" ).off( "focusin", "input", fn );   // remove delegated handler

Official jQuery API example

jQuery
$( "p" ).on( "focusin", function() {
  $( this ).find( "span" ).css( "display", "inline" ).fadeOut( 1000 );
} );

Return value

  • .on() and .trigger() return the original jQuery object for chaining.
  • Handler return values are ignored unless you use return false (equivalent to preventDefault() + stopPropagation()).

⚡ Quick Reference

GoalCode
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)

📋 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

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.

jQuery
$( "p" ).on( "focusin", function() {
  $( this ).find( "span" ).css( "display", "inline" ).fadeOut( 1000 );
} );
Try It Yourself

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.

jQuery
$( "#signup-form" ).on( "focusin", "input", function() {
  $( "#signup-form input" ).removeClass( "active" );
  $( this ).addClass( "active" );
} );
Try It Yourself

How It Works

focusin bubbles from the input to the form. jQuery’s selector filter "input" ensures $(this) is the focused input, not the form element.

📈 Bubbling & Advanced Patterns

Compare focus vs focusin, pass eventData, and handle dynamically added fields.

Example 3 — focus vs focusin: Parent Handler Test

A handler on #wrapper only fires with focusin — not with direct focus binding on the wrapper.

jQuery
var log = [];

$( "#wrapper" ).on( "focus", function() {
  log.push( "focus on wrapper (will NOT run for nested input)" );
} );

$( "#wrapper" ).on( "focusin", function() {
  log.push( "focusin on wrapper (runs when input inside gains focus)" );
  $( "#out" ).text( log.join( " | " ) );
} );
Try It Yourself

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.

jQuery
$( "#profile-form" ).on( "focusin", { theme: "blue" }, "input", function( event ) {
  $( this ).css( "border-color", event.data.theme );
  $( "#out" ).text( "Focused: " + $( this ).attr( "name" ) + " | theme: " + event.data.theme );
} );
Try It Yourself

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.

jQuery
var count = 0;

$( "#dynamic-form" ).on( "focusin", "input", function() {
  $( "#dynamic-form input" ).removeClass( "active" );
  $( this ).addClass( "active" );
  $( "#status" ).text( "Active: " + $( this ).attr( "name" ) );
} );

$( "#add-field" ).on( "click", function() {
  count += 1;
  $( "#dynamic-form" ).append(
    '<input type="text" name="extra' + count + '" placeholder="Extra ' + count + '">'
  );
} );
Try It Yourself

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.

🚀 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.

📝 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 focusin bubbles — 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").

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
focusin Universal

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.

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.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Six things to remember about the focusin event

Bubble, delegate, parent forms.

6
Core concepts
form 02

Delegate

One bind

Dynamic
03

vs focus

No bubble

Compare
out 04

focusout

Exit pair

Pair
p 05

<p> demo

Official

API
.off 06

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

Next: .focus() Method

Legacy shorthand — read and migrate older focus binding code.

.focus() tutorial →

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.

6 people found this page helpful