W3Schools.com

jQuery Event keydown() Method

jQuery Event Methods jQuery Event Methods

Example

Change the background color of an input field each time a key is pressed:

$("input").keydown(function(){
  $("input").css("background-color","#FFFFCC");
});

Try it yourself »

Definition and Usage

A key press has two parts: 1. The key is pressed down. 2. The key is released.

The keydown event occurs when a keyboard key is pressed down.

The keydown() method triggers the keydown event, or specifies a function to run when a keydown event occurs.

Tip: Use the event.which property to return which key was pressed.


Trigger the keydown Event

Trigger the keydown event for the selected elements.

Syntax

$(selector).keydown()

Try it yourself »


Bind a Function to the keydown Event

Specifies a function to run when the keydown event occurs for the selected elements.

Syntax

$(selector).keydown(function)

Try it yourself »

Parameter Description
function Optional. Specifies the function to run when the keydown event occurs


Examples

Try it Yourself - Examples

Determine which key was pressed
How to determine which key was pressed.


jQuery Event Methods jQuery Event Methods


WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Best Website Templates Top CSS Templates
CREATE HTML Websites
EASY WEBSITE BUILDER
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE