jQuery Keyup Event

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

What You’ll Learn

The keyup event fires when the user releases a key — once per press-and-release cycle, with no repeat while held. This tutorial covers .on("keyup"), event.which key codes, eventData, .trigger("keyup"), preventDefault for Enter, document-level shortcuts, and the official jQuery API demos.

01

.on()

Bind handler

02

event.which

Key code

03

.trigger()

Fire keyup

04

Focus

Target element

05

release

Key up

06

Since 1.7

Modern API

Introduction

Sometimes you need to know when the user finished pressing a key — not when it first went down. The keyup event fires when a key comes back up, after the character has appeared in an input and after any keydown handlers have run.

The official jQuery API describes the keyup event (bound with .on("keyup") since 1.7) separately from the deprecated .keyup() method. To programmatically run keyup handlers, use .trigger("keyup") since jQuery 1.0. For catching actual text entry as characters, keypress or the native input event may fit better — but keyup is ideal for reacting after each key release.

Understanding the keyup Event

The keyup event is sent to an element when the user releases a key on the keyboard. It fires once per key release — not repeatedly while the key is held down.

It can be attached to any element, but the event is only delivered to the element that has focus. Form elements — <input>, <textarea>, and <select> — are always reasonable targets. For page-wide shortcut keys, attach the handler to document so bubbling brings every key release to your code.

💡
Pair with keydown

Use keydown to detect when a key goes down (including repeats while held) and keyup to detect when it comes back up. On both events, examine event.which — jQuery normalizes key codes like 13 (Enter) and 27 (Escape) across browsers.

📝 Syntax

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

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

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

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

jQuery
$( "#app" ).on( "keyup", "input", function( event ) {
  // runs when any input inside #app receives a keyup — including future ones
} );

Keyboard events bubble, so delegation on a parent container works for dynamic forms and lists of inputs.

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

jQuery
.trigger( "keyup" )
  • Runs bound keyup handlers on the matched element(s).
  • Does not simulate a real OS key repeat — it fires handlers once per call.

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

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

Official jQuery API examples

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

$( "#other" ).on( "click", function() {
  $( "#target" ).trigger( "keyup" );
} );

Return value

  • .on() and .trigger() return the original jQuery object for chaining.
  • Returning false from the handler can cancel default actions — same as preventDefault() + stopPropagation().

⚡ Quick Reference

GoalCode
Bind keyup handler$("#target").on("keyup", fn)
Read key codeevent.which — 13 Enter, 27 Escape
Pass data to handler$("#field").on("keyup", { max: 10 }, fn)
React after key release$("#field").on("keyup", fn) — runs once per keystroke
Global key release on page$(document).on("keyup", fn)
Trigger keyup programmatically$("#target").trigger("keyup")
Remove keyup handlers$("#target").off("keyup")

📋 keyup vs keydown vs keypress vs deprecated .keyup()

Four related keyboard concepts — know which fires when, and what each is best for.

keydown event
key down

Every key press including arrows and modifiers — repeats while held; use event.which

keypress event
char

Mainly printable characters — narrower; prefer keydown or input event in new code

keyup event
key up

Fires when key is released — pair with keydown for hold detection

.keyup() method
deprecated

Deprecated shorthand for keyup — use .on("keyup") and .trigger("keyup") instead

Examples Gallery

Examples 1–2 follow the official jQuery API documentation. Examples 3–5 extend the official counter demo with keydown+keyup pairing, held-key tracking, and live updates on key release. Use the Try-it links to run each snippet in the browser.

📚 Binding & Triggering

Official jQuery demos for keyup handlers and programmatic triggers.

Example 1 — Official Demo: Bind Handler on #target

Alert when a key is pressed and released while the input has focus — official jQuery API demo.

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

How It Works

.on("keyup", fn) runs when a key is released while #target has focus. Press and release a key inside the field — keyup does not fire on unfocused elements.

Example 2 — Official Demo: #other Triggers Keyup on #target

One button programmatically fires the keyup handler on the input.

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

$( "#other" ).on( "click", function() {
  $( "#target" ).trigger( "keyup" );
} );
Try It Yourself

How It Works

.trigger("keyup") synthetically fires the event. Bound handlers run, but no actual key code is set unless you pass a simulated event object.

📈 Key Codes & Release Patterns

Official extended demo plus practical patterns for pairing keydown/keyup and reacting after release.

Example 3 — Official Demo: Counter, event.which, and Enter preventDefault

Count keyup events, block Enter from submitting, and log the event object — from the jQuery API documentation.

jQuery
var xTriggered = 0;

$( "#target" ).on( "keyup", function( event ) {
  xTriggered++;
  var msg = "Handler for `keyup` called " + xTriggered + " time(s).";
  $( "#log" ).prepend( "
" + msg + " Key: " + event.which + "
" ); } ).on( "keydown", function( event ) { if ( event.which == 13 ) { event.preventDefault(); } } ); $( "#other" ).on( "click", function() { $( "#target" ).trigger( "keyup" ); } );
Try It Yourself

How It Works

The official API pairs keydown (to block Enter with preventDefault) and keyup (to count releases and log event.which). Enter prevention belongs on keydown; release detection belongs on keyup.

Example 4 — Pair keydown and keyup for Hold Detection

Track when a key goes down and when it comes back up — essential for games and modifier-key state.

jQuery
var keysDown = {};

$( "#target" ).on( "keydown", function( event ) {
  keysDown[ event.which ] = true;
  $( "#down" ).text( "Keys held: " + Object.keys( keysDown ).join( ", " ) );
} ).on( "keyup", function( event ) {
  delete keysDown[ event.which ];
  $( "#up" ).text( "Key released: " + event.which );
  $( "#down" ).text( "Keys held: " + ( Object.keys( keysDown ).length ? Object.keys( keysDown ).join( ", " ) : "none" ) );
} );
Try It Yourself

How It Works

keydown adds the key code to a map; keyup removes it. This pattern avoids guessing from keydown repeats alone — the map always reflects keys currently held down.

Example 5 — Live Field Update on keyup

Update a character count or validation message after each key release — common in search and form fields.

jQuery
$( "#search" ).on( "keyup", function( event ) {
  var len = $( this ).val().length;
  var lastKey = event.which === 8 ? "Backspace" : String.fromCharCode( event.which );
  $( "#status" ).text(
    "Length: " + len + " | Last key released: " + lastKey
  );
} );
Try It Yourself

How It Works

keyup runs after the browser inserts the character, so $(this).val() is up to date. This is a simple pattern for live counters; production search often debounces on input or keyup.

🚀 Common Use Cases

  • Post-keystroke validation — check field length or format after each key release on keyup.
  • Hold detection — pair keydown + keyup to track which keys are currently held.
  • Modifier release — detect when Shift or Ctrl is released via keyup on document.
  • Live character counts — update UI after each key release in text fields.
  • Live search — react on keyup after release (often paired with debounce).
  • Debugging — log event.which during development to learn key codes.

🚀 How the keyup Event Flows

1

User releases key

Physical key comes back up while an element (or document) has focus — or code calls .trigger("keyup").

release
2

keyup event fires

Handler runs on the focused element. Event object includes which, shiftKey, ctrlKey, and altKey.

keyup
3

Handler decides

Compare event.which, update UI, clear held-key state, or run validation after the keystroke completes.

which?
4

Bubble once

Event bubbles to ancestors (e.g. document). One keyup per press-and-release — no repeat while held.

📝 Notes

  • Bind with .on("keyup", handler) since jQuery 1.7 — not the deprecated .keyup(handler) method.
  • Trigger with .trigger("keyup") since jQuery 1.0.
  • Event is sent only to the element with focus — click or tab into inputs first.
  • Use event.which for key codes — jQuery normalizes cross-browser differences.
  • keyup does not repeat while held — one event per key release.
  • For global shortcuts, bind on document — events bubble up from focused children.
  • For printable text input, consider the native input event — keyup fires after the character appears in the field.
  • Use .off("keyup") to remove handlers — avoid deprecated .unbind("keyup").

Browser Support

The keyup event is a standard DOM keyboard event supported in every browser jQuery targets. jQuery’s .on("keyup") (since 1.7) and .trigger("keyup") (since 1.0) normalize event.which for consistent key codes.

jQuery 1.7+

jQuery keyup 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('keyup', 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
keyup Universal

Bottom line: Safe in any jQuery project. Prefer .on('keyup') over deprecated .keyup() for binding. Use event.which for key codes.

Conclusion

The jQuery keyup event is the standard hook for reacting when keys are released — live validation, hold detection with keydown, and post-keystroke UI updates. Bind handlers with .on("keyup", fn), read event.which for key codes, and fire handlers programmatically with .trigger("keyup").

Remember: keyup requires focus on the target element unless you bind on document. Pair with keydown when you need both press and release. For dynamic pages, delegate with $("#app").on("keyup", "input", fn).

💡 Best Practices

✅ Do

  • Bind with .on("keyup", handler) on inputs or document
  • Use event.which for reliable key codes across browsers
  • Pair keydown + keyup for accurate held-key tracking
  • Set tabindex="0" on custom focusable widgets
  • Check event.ctrlKey / shiftKey for modifier shortcuts

❌ Don’t

  • Use deprecated .keyup(handler) in new code — prefer .on("keyup")
  • Expect keyup on elements that never receive focus
  • Confuse keyup with keydown — keydown repeats while held, keyup does not
  • Use keyup alone for movement that should repeat while held — use keydown instead
  • Hard-code browser-specific key properties — use event.which

Key Takeaways

Knowledge Unlocked

Six things to remember about the keyup event

Release, code, pair.

6
Core concepts
which 02

event.which

Key code

Detect
03

.trigger()

Fire

Programmatic
focus 04

Focus

Required

Target
doc 05

document

Global

Shortcut
06

Repeats

While held

OS

❓ Frequently Asked Questions

The keyup event fires when the user releases a key on the keyboard. Unlike keydown, it does not repeat while a key is held — one keyup per press-and-release cycle. Bind handlers with .on('keyup', handler) since jQuery 1.7. The event is only sent to the element that has focus.
keydown fires when a key goes down and repeats while held (OS key repeat). keyup fires once when the key comes back up. Both report the same event.which key codes. Use keydown for shortcuts and movement; use keyup when you need to react after the user finishes pressing a key.
Read event.which — jQuery normalizes this property across browsers. Common codes: 13 Enter, 27 Escape, 32 Space, 37–40 arrow keys, 65–90 letter A–Z. The code reflects which key was released.
Call $('#target').trigger('keyup') since jQuery 1.0. Bound keyup handlers run. Note that .trigger() does not simulate a full physical key press and release — it only runs jQuery-bound handlers once per call.
Use keyup for validation after typing, live character counts, detecting when a modifier key is released, or any logic that should run once per keystroke after the character appears in the field. Use keydown for immediate shortcuts, games, and keys that repeat while held.
The target element must have focus when the key is released. Click inside an input first, or set tabindex on custom widgets. If you press a key outside the focused element, keyup goes to whatever has focus. For page-wide detection, bind on document.
Did you know?

jQuery’s $.event.special layer maps keyboard events consistently so event.which works even when older browsers exposed different properties (keyCode, charCode). That is why the official API recommends event.which instead of reading raw browser fields — one number for Enter, Escape, and arrow keys everywhere jQuery runs.

Next: .keyup() method

Learn the deprecated shorthand for binding and triggering keyup — and how to migrate to .on("keyup").

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