Example 1 — Bind with .keypress(handler)
Legacy bind — runs when a printable key is typed while the input has focus.
$("#target").keypress(function () {
console.log("Handler for keypress called.");
}); How It Works
- Select the input.
$("#target")must be focusable. - Call the shorthand.
.keypress(fn)registers the handler (internally uses.on). - Type a character. Printable input fires the handler; the message logs.

