English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery event.which property

jQuery Events

The 'event.which' property returns which key on the keyboard or mouse button was pressed.

Syntax:

event.which

Example

Display which key was pressed (ASCII value):

$("input").keydown(function(event){ 
  $("div").text("Key:  "); + event.which);
});
Test See‹/›

Display which key was pressed:

$("input").keydown(function(event){ 
  $("div").append(String.fromCharCode(event.which));
});
Test See‹/›

Check if the space key was pressed within the <input> field:

$("input").keydown(function(event){ 
  if(event.which === 32{
$("div").text("You pressed'SPACE#39; Space key");
  }
});
Test See‹/›

Display which mouse button was pressed:

$("div").mousedown(function(event){ 
  $(this).append("<br>Mouse button pressed:  "); + event.which);
});
Test See‹/›

parameter value

parameterdescription
eventTheeventparameter comes from the event binding feature

jQuery Events