Example 1 — Bind with .keydown(handler)
Legacy bind — runs when a key is pressed while the input has focus.
$("#target").keydown(function () {
console.log("Handler for keydown called.");
}); How It Works
- Select the input.
$("#target")must be focusable. - Call the shorthand.
.keydown(fn)registers the handler (internally uses.on). - Press a key. The handler runs on press; hold may repeat.

