jQuery :focus Selector — Match the Focused Element
Beginner
7 min read
Updated: Oct 2026
5 examples
Live preview
Definition
What Is the :focus Selector?
:focus (since jQuery 1.6) selects the element that currently has focus — for example the input you are typing in. Like other : pseudo-classes, precede it with a tag or other selector when possible.
Remember
$("input:focus"); // focused input
$("#form :focus"); // focused control inside a form
$("input").is(":focus"); // true if that input has focus
// Prefer for a single lookup:
$(document.activeElement);
// Bare $(":focus") ≡ $("*:focus") — avoid
Query on demand, or listen for focus/blur and test with .is(":focus").
Prefer a tagged or scoped selector ($("input:focus"), $("#form :focus")).
For a one-off “what has focus?”, use $(document.activeElement).
To style live focus, listen for focus/blur (or focusin/focusout).
After focus moves, a setTimeout(…, 0) can let .is(":focus") see the new state.
Only focusable elements match — inputs, buttons, links, tabindex, and similar.
Piece
Required?
Role
Selector prefix
Recommended
Tag, id, or container — avoid bare :focus
Return value
—
jQuery set of currently focused matches (usually 0 or 1)
Since
—
jQuery 1.6
Pseudocode
Pseudocode
call $(context).find(":focus") // or $("input:focus")
for each candidate element in the query:
if element is the document's focused node:
include it
return the jQuery set
// Fast path (no DOM scan):
// $(document.activeElement)
Reference
Cheat Sheet
Keep these facts handy while working with keyboard focus.
:focus has been part of jQuery since 1.6. It mirrors the standard CSS :focus pseudo-class and works in every browser that runs your loaded jQuery version.
✓ Stable · jQuery 1.6+
jQuery :focus
Supported across jQuery 1.x (1.6+), 2.x, and 3.x. Prefer a current jQuery 3.x build. Use tagged selectors and activeElement for fast lookups.
100%With jQuery
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
:focusUniversal
Bottom line: Safe for form UX and keyboard focus checks. Prefer $("input:focus") or $(document.activeElement) over bare $(":focus").
Analysis
Performance Notes
Approach
Cost
Best for
$(document.activeElement)
Cheapest
Single focused element lookup
$("input:focus") / scoped form
Cheap
Filtering a known set
$(":focus") / $("*:focus")
Wider scan
Avoid in hot paths
Focus queries are usually tiny (0–1 matches). Cost comes from scanning too broadly — scope the selector, or skip the selector and read document.activeElement.
Remember
Key Takeaways
Role: match the currently focused element — since jQuery 1.6.
Prefer:$("input:focus") or $("#form :focus") over bare :focus.
Fast path:$(document.activeElement) for one node.
Race: use setTimeout(0) before .is(":focus") on blur.
One line::focus finds the element that has keyboard focus — scope it, or use document.activeElement for a direct read.
Frequently Asked Questions
:focus selects elements that currently have keyboard or pointer focus. $("input:focus") matches the input the user is typing in right now. Available since jQuery 1.6.
Bare :focus implies the universal selector — equivalent to $("*:focus"), which searches every element type. Prefer $("input:focus"), $("button:focus"), or $("#form :focus") for clarity and performance.
Official jQuery docs: if you only need the single currently focused element, $(document.activeElement) retrieves it without searching the whole DOM tree. Use :focus when filtering a scoped collection — for example $("form input:focus").
Yes. :focus is standard CSS and works in native querySelectorAll when prefixed — for example document.querySelectorAll("a:focus"). jQuery has supported it since 1.6.
When focus moves from one element to another, blur and focus fire in quick succession. A short setTimeout lets the browser update document.activeElement before elem.is(":focus") runs — so a focused class toggles correctly.
Focusable elements include inputs, buttons, links, selects, textareas, and any element with a tabindex. Disabled controls and purely decorative nodes typically cannot hold focus.