jQuery .keyup() Method

Beginner
⚠️ Deprecated since 3.3
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Keyboard events

What You’ll Learn

The .keyup() method is jQuery’s legacy shorthand for binding and triggering the keyup event. This tutorial covers .keyup(handler) since 1.0, .keyup(eventData, handler) since 1.4.3, no-argument .keyup() as a trigger, migration to .on("keyup") and .trigger("keyup"), and why the binding form is deprecated since jQuery 3.3. See the jQuery keyup event tutorial for the modern API.

01

.keyup(fn)

Bind handler

02

eventData

Since 1.4.3

03

.keyup()

Trigger event

04

.on()

Modern bind

05

.trigger()

Modern fire

06

Deprecated

Since 3.3

Introduction

Before jQuery 1.7 unified events with .on() and .off(), every common event had a matching shorthand — .keyup(), .keydown(), .click(), and more. The .keyup() method let you react when keys are released in one short call: $("#search").keyup(function(){ updateCount(); }). It remains in jQuery 3.x for backward compatibility but is marked deprecated.

Understanding .keyup() matters when reading older search fields and post-keystroke validation tutorials in legacy codebases. The method does two distinct jobs: with a function argument it binds; with no arguments it triggers. Modern jQuery splits those roles explicitly — .on("keyup", handler) for binding and .trigger("keyup") for firing.

⚠️
Focus required

The jQuery .keyup() method attaches to any element, but the browser only delivers keyup events to the element that has focus. Click inside an input or set tabindex="0" on custom widgets before expecting handlers to run. keyup fires when any key is released — pair with .on("keydown") when you need both press and release.

Understanding the .keyup() Method

The official jQuery API describes .keyup() as a way to bind an event handler to the keyup event, or trigger that event on an element. When you pass a handler, jQuery registers it on each matched element and calls it when the user presses a key while that element has focus — the same keyup event that .on("keyup") handles today.

When you call .keyup() with no arguments, jQuery synthetically fires the keyup event on each matched element. Bound handlers run once per call. This trigger behavior is equivalent to .trigger("keyup").

⚠️
Deprecated since jQuery 3.3

Do not use .keyup(handler) or .keyup(eventData, handler) in new code. Replace them with .on("keyup", handler) or .on("keyup", eventData, handler). Replace no-argument .keyup() with .trigger("keyup"). For event.which key codes, keydown pairing, and the full modern keyup guide, read the jQuery keyup event tutorial.

📝 Syntax

The .keyup() method has three signatures from the official jQuery API. The binding forms are deprecated; the trigger form remains valid but .trigger("keyup") is preferred:

1. Bind a handler — .keyup( handler ) (since 1.0, deprecated 3.3)

jQuery
.keyup( handler )
  • handler — function executed each time keyup fires: function( event ) { ... }.
  • Returns the jQuery object for chaining.
  • Modern replacement: .on( "keyup", handler ).

2. Bind with eventData — .keyup( [eventData], handler ) (since 1.4.3, deprecated 3.3)

jQuery
.keyup( [eventData], handler )
  • eventData — optional object available in the handler as event.data.
  • Modern replacement: .on( "keyup", eventData, handler ).

3. Trigger the event — .keyup() (since 1.0)

jQuery
.keyup()
  • No arguments — triggers keyup on every matched element.
  • Runs bound keyup handlers.
  • Preferred replacement: .trigger( "keyup" ).

Official jQuery API migration note

jQuery
// Deprecated binding
$( "#target" ).keyup( function() {
  alert( "Handler for `keyup` called." );
} );

// Modern binding
$( "#target" ).on( "keyup", function() {
  alert( "Handler for `keyup` called." );
} );

// Deprecated trigger
$( "#target" ).keyup();

// Modern trigger
$( "#target" ).trigger( "keyup" );

Return value

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

⚡ Quick Reference

GoalLegacy (.keyup)Modern replacement
Bind keyup handler$("#target").keyup(fn)$("#target").on("keyup", fn)
Pass data to handler$("#search").keyup({ fieldId: "search" }, fn)$("#search").on("keyup", { fieldId: "search" }, fn)
Trigger keyup programmatically$("#target").keyup()$("#target").trigger("keyup")
Trigger on matched elements$("input").keyup()$("input").trigger("keyup")
Remove keyup handlers$("#target").off("keyup")$("#target").off("keyup")
Delegated keyup on inputs$("#app").on("keyup", "input", fn) — not available via .keyup()
event.which — key code: 13 Enter, 27 Escape, 32 Space

📋 .keyup() vs .on("keyup") vs .trigger("keyup") vs .off("keyup")

Four related APIs — know which one binds, which one fires, and which one removes handlers.

.keyup()
deprecated

Legacy bind (.keyup(fn)) or trigger (.keyup()) — use modern APIs for new code

.on("keyup")
bind

Modern binding since 1.7 — supports eventData and delegation on dynamic inputs

.trigger("keyup")
fire

Programmatically run handlers — clearer than no-arg .keyup()

.off("keyup")
remove

Unbind handlers — pair with .on("keyup") when cleaning up or in SPAs

Examples Gallery

Five examples cover binding, eventData, triggering, migration from .keyup() to .on("keyup"), and method chaining. Use the Try-it links to run each snippet in the browser. Remember: binding with .keyup(handler) is deprecated — these demos show legacy syntax you will encounter in older code.

📚 Binding & Triggering

Legacy .keyup() signatures for binding handlers and firing events programmatically.

Example 1 — Bind Handler with .keyup(handler)

The canonical legacy pattern — alert when a key is released while the input has focus.

jQuery
$( "#target" ).keyup( function() {
  alert( "Handler for \`keyup\` called." );
} );
Try It Yourself

How It Works

.keyup(fn) registers the function on the element. jQuery internally routes this to .on("keyup", fn). The handler runs once when a key is released while the element has focus.

Example 2 — Pass eventData with .keyup(eventData, handler)

Since jQuery 1.4.3, pass field metadata before the handler — it arrives as event.data.

jQuery
$( "#search" ).keyup( { fieldId: "search" }, function( event ) {
  $( "#out" ).text(
    "Field: " + event.data.fieldId + " | key code: " + event.which
  );
} );
Try It Yourself

How It Works

jQuery stores the { fieldId: "search" } object and injects it into event.data when keyup fires. Modern equivalent: .on("keyup", { fieldId: "search" }, fn).

Example 3 — Trigger Keyup with No-Argument .keyup()

Calling .keyup() without a handler fires the keyup event programmatically — bound handlers run once per call.

jQuery
var count = 0;

$( "#target" ).keyup( function( event ) {
  count++;
  $( "#out" ).text( "Target keyup handler fired (count: " + count + ")" );
} );

$( "#fire" ).click( function() {
  $( "#target" ).keyup();
} );
Try It Yourself

How It Works

The first .keyup(function(){ ... }) binds a handler on #target. The button calls $("#target").keyup() with no arguments — that synthetically fires keyup. Replace with $("#target").trigger("keyup") for clarity.

📈 Migration & Chaining

Compare legacy and modern APIs, and chain after .keyup(handler).

Example 4 — Migration: .keyup(fn) vs .on("keyup", fn)

Both bind the same keyup event — .on() is the recommended API for new code.

jQuery
$( "#legacy" ).keyup( function() {
  $( "#out" ).text( "Legacy: .keyup(function(){ ... }) — deprecated since jQuery 3.3." );
} );

$( "#modern" ).on( "keyup", function() {
  $( "#out" ).text( "Modern: .on('keyup', function(){ ... }) — use this for new code." );
} );
Try It Yourself

How It Works

Under the hood, .keyup(fn) calls .on("keyup", fn). Migration is a straight rename with no behavior change for simple bindings. The advantage of .on() is delegation — $("#app").on("keyup", "input", fn) — which .keyup() cannot do.

Example 5 — Chaining After .keyup(handler)

.keyup(handler) returns the jQuery object — chain multiple release handlers on the same input.

jQuery
$( "#target" )
  .keyup( function( event ) {
    $( "#notice" ).text( "First handler: key " + event.which + " released." ).show();
  } )
  .keyup( function( event ) {
    $( "#result" ).text( "Second handler: field length " + $( "#target" ).val().length );
  } );
Try It Yourself

How It Works

Multiple .keyup(fn) calls stack handlers — all run when a key is released. Value is up to date because keyup fires after the character is inserted. Same pattern works with .on("keyup", fn).

🚀 Common Use Cases

  • Reading legacy code — recognize $("#search").keyup(fn) as equivalent to .on("keyup", fn) in older scripts.
  • Post-keystroke validation — legacy fields bind .keyup() to validate after each key release.
  • Programmatic trigger$("#target").keyup() from a test button — replace with .trigger("keyup").
  • Shared eventData$("#field").keyup({ id: "search" }, fn) passes metadata without closures.
  • Live character counts — chained .keyup(fn) calls update UI after each key release.
  • Maintaining legacy search UIs — many jQuery 1.x panels still use .keyup() — know how to migrate safely.

🧠 How .keyup() Routes Through jQuery

1

You call .keyup()

With a function argument, jQuery treats it as a bind request. With no arguments, it treats it as a trigger request.

dispatch
2

Bind path

.keyup(handler) delegates internally to .on("keyup", handler) — the handler is stored in jQuery’s event system.

.on("keyup")
3

Trigger path

No-arg .keyup() delegates to .trigger("keyup") — bound handlers run when keyup fires.

.trigger("keyup")
4

jQuery object returned

Both paths return the original collection for chaining — .keyup(fn).addClass("watched") works the same as .on("keyup", fn).addClass("watched").

📝 Notes

  • Deprecated since jQuery 3.3 — do not use .keyup(handler) or .keyup(eventData, handler) in new code. Use .on("keyup") instead.
  • Bind with .keyup(handler) since jQuery 1.0; eventData form since 1.4.3.
  • No-argument .keyup() triggers the event since jQuery 1.0 — prefer .trigger("keyup").
  • .keyup() does not support event delegation — use .on("keyup", "input", fn) for dynamic forms.
  • Keyboard events require focus on the target element — click or tab into inputs first.
  • Read key codes with event.which inside handlers — on keyup this is the typed character, not the physical key.
  • Remove handlers with .off("keyup") — not by calling .keyup(undefined).
  • For the full modern keyup guide — event.which key codes, keydown pairing, and release patterns — see the jQuery keyup event tutorial.

Browser Support

The underlying keyup event fires on focused elements in browsers jQuery targets. The .keyup() method itself is a jQuery API — it works in jQuery 1.x, 2.x, and 3.x. Binding via .keyup(handler) is deprecated since 3.3 but still functional; triggering via no-arg .keyup() also remains supported.

jQuery 1.0+

jQuery .keyup() method

Supported across all jQuery versions you are likely to maintain. Deprecated binding since 3.3 — use .on('keyup') for new projects. Native equivalent for binding: element.addEventListener('keyup', fn). Native equivalent for trigger: .trigger('keyup') or dispatchEvent.

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
.keyup() Legacy API

Bottom line: Safe in legacy jQuery projects. Migrate bindings to .on('keyup') and triggers to .trigger('keyup') when updating legacy search and post-keystroke validation code.

Conclusion

The jQuery .keyup() method is the legacy shorthand for binding and triggering keyup handlers. Use .keyup(handler) or .keyup(eventData, handler) to bind — both deprecated since jQuery 3.3. Use no-argument .keyup() to trigger — equivalent to .trigger("keyup").

For new code, prefer .on("keyup", fn) for binding and .trigger("keyup") for programmatic firing. When you encounter .keyup() in older search and validation scripts, recognize it, understand it, and migrate when practical. For event.which, keydown pairing, and the complete modern keyup workflow, continue with the jQuery keyup event tutorial.

💡 Best Practices

✅ Do

  • Use .on("keyup", handler) for all new keyup bindings
  • Use .trigger("keyup") instead of no-arg .keyup()
  • Migrate .keyup(fn) to .on("keyup", fn) when refactoring legacy files
  • Use .off("keyup") to remove handlers cleanly
  • Read the modern keyup event tutorial for keydown pairing and live-update patterns

❌ Don’t

  • Write new keyboard handlers with deprecated .keyup(handler)
  • Expect keyup on elements that never receive focus
  • Use keyup alone for movement that should repeat while held — use keydown instead
  • Assume .keyup() supports delegation — it does not
  • Confuse .keyup(fn) (bind) with .keyup() (trigger)
  • Use .unbind("keyup") — it is also deprecated; use .off("keyup")
  • Copy deprecated patterns from old tutorials without modernizing them

Key Takeaways

Knowledge Unlocked

Six things to remember about .keyup()

Legacy bind, modern migrate.

6
Core concepts
data 02

eventData

Since 1.4.3

Handler
() 03

.keyup()

Trigger

No args
.on 04

.on("keyup")

Modern

Replace
05

.trigger()

Fire

Programmatic
3.3 06

Deprecated

Since 3.3

Migrate

❓ Frequently Asked Questions

The .keyup() method has two roles. With a handler argument — .keyup(handler) or .keyup(eventData, handler) — it binds a function that runs when the user releases a key on a matched element that has focus. With no arguments — .keyup() — it triggers the keyup event on each matched element, running bound handlers. Both forms have been part of jQuery since 1.0; the binding form is deprecated since 3.3.
Yes — the binding signatures .keyup(handler) and .keyup(eventData, handler) are deprecated since jQuery 3.3. Use .on('keyup', handler) or .on('keyup', eventData, handler) instead. The no-argument .keyup() trigger form still works but .trigger('keyup') is clearer and preferred in modern code.
.keyup(handler) registers a callback — it does not fire the event immediately. .keyup() with no arguments triggers the keyup event programmatically on every matched element, the same as .trigger('keyup'). The handler form is deprecated for binding; the no-arg form is a trigger shorthand.
Replace .keyup(fn) with .on('keyup', fn). Replace .keyup(data, fn) with .on('keyup', data, fn). Replace no-arg .keyup() with .trigger('keyup'). Replace .unbind('keyup') cleanup with .off('keyup'). Under the hood, .keyup(handler) already delegates to .on('keyup') — migration is a straight rename.
Yes. jQuery 3.x keeps .keyup() for backward compatibility. It still binds and triggers correctly. The API docs mark it deprecated to steer new projects toward .on() and .trigger(). Do not use .keyup(handler) in new code — prefer the modern API in the keyup event tutorial.
No — keyup fires once when the key is released, not while it is held down. keydown repeats during a hold; keyup does not. .keyup(handler) follows the same browser rule: one handler call per key release.
Did you know?

jQuery event shorthands like .keyup(handler) were thin wrappers around .bind("keyup", handler) before .on() unified the API in jQuery 1.7. When you call .keyup(fn) today, jQuery still routes through the same event system as .on("keyup", fn) — which is why migration is a rename with no behavior change for simple bindings.

Next: focus event

Learn how elements gain keyboard focus — required for keyup to fire.

focus event 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