jQuery Keyup Event

Beginner
5 min read
Updated: Nov 2026
3 examples
Keyboard Events

Definition

The keyup event fires when the user releases a key. It runs once per press-and-release — it does not repeat while held (unlike keydown). Bind with .on("keyup") since jQuery 1.7; the event reaches only the focused element.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("#target").on("keyup", handler)   // bind (1.7+)
$("#target").trigger("keyup")       // fire handlers (1.0+)

event.which → key code (same idea as keydown)
  Enter 13 · Esc 27 · Space 32 · arrows 37–40 · A–Z 65–90

keydown → may repeat while held
keyup   → once when the key comes up
CallWhat it does
KeyupLearn the jQuery keyup event: bind with .on('keyup'), read key codes via event.which on release, trigger handlers, compare keyup vs keydown, examples, pitfalls, and FAQs.

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Pick a focusable target — usually an <input> or <textarea>.
Step 2Bind with $("#target").on("keyup", handler) (jQuery 1.7+).
Step 3Read event.which for the key code of the released key.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

Example 1 — Bind a Keyup Handler

Log when a key is released while the input has focus.

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

How It Works

  1. Select the input. $("#target") must be able to receive focus.
  2. Bind keyup. .on("keyup", fn) registers the handler (jQuery 1.7+).
  3. Release a key. After press-and-release, the handler runs once.

Example 2 — Trigger Keyup from a Button

Fire the bound handler programmatically with .trigger("keyup").

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

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

How It Works

  1. Bind first. Same handler as Example 1 on #target.
  2. Click the button. The click handler runs $("#target").trigger("keyup").
  3. Handlers fire once. Bound keyup listeners run; this is not a full OS key simulation.

Example 3 — Count Releases and Read event.which

Count keyup events and show the key code — official API demo style.

jQuery
var count = 0;

$("#target").on("keyup", function (event) {
  count++;
  $("#log").text(
    "Called " + count + " time(s). Key: " + event.which
  );
}).on("keydown", function (event) {
  if (event.which === 13) {
    event.preventDefault();
  }
});
Try It Yourself

How It Works

  1. Count each release. Every keyup increments count.
  2. Read event.which. On keyup this is the key code (e.g. 65 for A).
  3. Block Enter early. Official demo pairs keydown preventDefault for Enter (13).

Frequently Asked Questions

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

Next: .keyup() Method — Deprecated Event Shorthand

Learn the deprecated shorthand and how to migrate to .on("keyup").

.keyup() Method — Deprecated Event Shorthand tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

10 people found this page helpful