.keypress() is jQuery’s legacy shorthand for the keypress event (since 1.0). Pass a handler to bind; call it with no arguments to trigger. Binding forms are deprecated since jQuery 3.3.
Recognize the shorthand in old code, then migrate to .on / .trigger.
Find .keypress(fn) or bare .keypress() in legacy scripts.
Rewrite binds as .on("keypress", fn) (add eventData as the middle arg if needed).
Rewrite triggers as .trigger("keypress").
Keep using event.which for character codes — that part does not change.
Piece
Required?
Role
handler
For bind
function(event) { … }
eventData
Optional
Object → event.data (since 1.4.3)
No args
—
Trigger keypress on matched elements
Return
—
jQuery object (chainable)
Pseudocode
Pseudocode
if called with handler:
// deprecated since 3.3
bind handler to "keypress" on each element
(same as .on("keypress", handler))
if called with (eventData, handler):
bind with data → event.data
(same as .on("keypress", eventData, handler))
if called with no arguments:
fire "keypress" on each matched element
(same as .trigger("keypress"))
Reference
Cheat Sheet
Legacy vs modern — keep this table for quick migrations.
Legacy
Modern
$("#el").keypress(fn)
$("#el").on("keypress", fn)
$("#el").keypress(data, fn)
$("#el").on("keypress", data, fn)
$("#el").keypress()
$("#el").trigger("keypress")
Delegation
Only via .on("keypress", "input", fn)
Unbind
$("#el").off("keypress")
Status
Deprecated since jQuery 3.3
Try it
Live Preview
Compare the deprecated shorthand with the modern API. Type in the field, or click Trigger to fire handlers.
Browser demo of .keypress() vs .on("keypress") — same event underneath.
Result
$("#field").keypress(fn) // deprecated bind
→ type a letter to fire
/* prefer .on("keypress", fn) */
Code
jQuery Examples
Short demos of the legacy shorthand and how to migrate. Prefer .on / .trigger in new code.
Example 1 — Bind with .keypress(handler)
Legacy bind — runs when a printable key is typed while the input has focus.
jQuery
$("#target").keypress(function () {
console.log("Handler for keypress called.");
});
Both styles bind and fire the same keypress event
→ console logs "legacy" then "modern" when triggered
Use only the modern form in new projects
How It Works
Two equivalent binds. Shorthand and .on attach the same event type.
Two equivalent triggers. Bare .keypress() matches .trigger("keypress").
No behavior change. Migration is naming, not a rewrite of handler logic.
One style going forward. Stick to .on / .trigger / .off.
Edge Cases & Pitfalls
Watch for these when reading or migrating .keypress().
deprecated
Do not use in new code
Binding with .keypress(fn) is deprecated since 3.3. Write .on("keypress", fn).
overload
Bind vs trigger look alike
.keypress(fn) binds; .keypress() triggers. Easy to confuse when skimming. Modern APIs make the intent obvious.
delegation
No selector form
.keypress() cannot delegate. Use $("#app").on("keypress", "input", fn) for dynamic fields.
event
Same keypress limits
Still needs focus; still skips arrows/modifiers. For all keys use keydown; for text values prefer the input event.
Compatibility
Browser Support
.keypress() has been available since jQuery 1.0 (eventData since 1.4.3) and is deprecated since jQuery 3.3. Prefer .on("keypress") / .trigger("keypress") everywhere jQuery runs.
✓ Deprecated · jQuery 3.3
jQuery .keypress()
Works in Chrome, Firefox, Safari, and Edge with jQuery 1.0+. Still present in jQuery 3.x for compatibility. New code should use .on('keypress') and .trigger('keypress').
LegacyPrefer .on / .trigger
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
.keypress()Deprecated
Bottom line: Learn .keypress() to read legacy code. Write .on("keypress", fn) and .trigger("keypress") in new projects.
Analysis
Performance Notes
Approach
Cost
Best for
.keypress(fn) / .on("keypress", fn)
Same
Shorthand is a thin alias — no speed win
.on("keypress", "sel", fn)
One listener
Dynamic inputs (delegation)
Heavy work per key
Noticeable
Keep handlers light; debounce search
Migrating to .on does not change performance — it clarifies intent and unlocks delegation. Optimize the handler body, not the binding API.
Remember
Key Takeaways
Role: legacy bind/trigger shorthand for the keypress event.
Status: binding forms deprecated since jQuery 3.3.
Migrate:.on("keypress", fn) and .trigger("keypress").
Event: same printable-character rules as the keypress event.
One line:.keypress() is the old name — learn it for legacy code, write .on("keypress") / .trigger("keypress") for new work.
Frequently Asked Questions
With a handler — .keypress(handler) or .keypress(eventData, handler) — it binds a function for printable keyboard input on a focused element. With no arguments — .keypress() — it triggers the keypress event and runs bound handlers. Binding forms are deprecated since jQuery 3.3.
Yes. Since jQuery 3.3, .keypress(handler) and .keypress(eventData, handler) are deprecated. Use .on('keypress', handler) instead. Prefer .trigger('keypress') over no-argument .keypress().
.keypress(fn) registers a callback and does not fire immediately. .keypress() with no arguments triggers keypress on each matched element — same idea as .trigger('keypress').
Replace .keypress(fn) with .on('keypress', fn). Replace .keypress(data, fn) with .on('keypress', data, fn). Replace bare .keypress() with .trigger('keypress'). Under the hood the shorthand already uses .on — migration is a rename.
Yes. jQuery 3.x keeps it for compatibility. It still binds and triggers. The docs mark it deprecated so new projects use .on() and .trigger(). See the keypress event tutorial for the modern API.
Arrows, Shift, Ctrl, and Escape are non-printing keys, so browsers usually skip keypress. Use .on('keydown', fn) when you need those keys.