jQuery .keyup() Method

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

Definition

.keyup() is jQuery’s legacy shorthand for the keyup event (since 1.0). Pass a handler to bind; call it with no arguments to trigger. Binding forms are deprecated since jQuery 3.3.

Syntax

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

jQuery
$("#el").keyup(fn)           // bind (deprecated)
$("#el").keyup(data, fn)     // bind + eventData (deprecated)
$("#el").keyup()             // trigger handlers

// Modern replacements:
$("#el").on("keyup", fn)
$("#el").trigger("keyup")
CallWhat it does
.keyup()Learn jQuery .keyup(): deprecated bind/trigger shorthand for keyup, migrate to .on('keyup') and .trigger('keyup'), eventData, examples, pitfalls, and FAQs.

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

Parameters

ParameterDescription
Step 1Find .keyup(fn) or bare .keyup() in legacy scripts.
Step 2Rewrite binds as .on("keyup", fn) (add eventData as the middle arg if needed).
Step 3Rewrite triggers as .trigger("keyup").

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

Legacy bind — runs when a key is released while the input has focus.

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

How It Works

  1. Select the input. $("#target") must be focusable.
  2. Call the shorthand. .keyup(fn) registers the handler (internally uses .on).
  3. Release a key. After press-and-release, the handler runs once.

Example 2 — Pass eventData

Since 1.4.3, pass an object before the handler — it arrives as event.data.

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

How It Works

  1. Pass data first. { fieldId: "search" } is stored with the handler.
  2. Read event.data. On keyup, the object is available without a closure.
  3. Use event.which. Still the key code on keyup (same family as keydown).

Example 3 — Trigger with No-Arg .keyup()

Calling .keyup() without a handler fires bound keyup listeners once.

jQuery
var count = 0;

$("#target").keyup(function () {
  count++;
  $("#out").text("Fired " + count + " time(s)");
});

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

How It Works

  1. Bind first. A handler is registered with the shorthand.
  2. Click fires it. Bare .keyup() triggers the event.
  3. Handlers run once. Not a full OS key simulation.

Frequently Asked Questions

With a handler — .keyup(handler) or .keyup(eventData, handler) — it binds a function that runs when the user releases a key on a focused element. With no arguments — .keyup() — it triggers the keyup event and runs bound handlers. Binding forms are deprecated since jQuery 3.3.
Yes. Since jQuery 3.3, .keyup(handler) and .keyup(eventData, handler) are deprecated. Use .on('keyup', handler) instead. Prefer .trigger('keyup') over no-argument .keyup().
.keyup(fn) registers a callback and does not fire immediately. .keyup() with no arguments triggers keyup on each matched element — same idea as .trigger('keyup').
Replace .keyup(fn) with .on('keyup', fn). Replace .keyup(data, fn) with .on('keyup', data, fn). Replace bare .keyup() with .trigger('keyup'). 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 keyup event tutorial for the modern API.
No. keyup fires once when the key is released. keydown can repeat during a hold; keyup does not. .keyup(handler) follows the same rule.

Next: Form Events

Learn how to react when an element gains keyboard focus.

Form Events 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.

9 people found this page helpful