Example 1 — Bind a Keydown Handler
Official style: log when a key is pressed while the input has focus.
$("#target").on("keydown", function () {
console.log("Handler for keydown called.");
}); How It Works
- Select the input.
$("#target")must be able to receive focus. - Bind keydown.
.on("keydown", fn)registers the handler (jQuery 1.7+). - Press a key. The handler runs immediately on press.

