jQuery keydown() Method

jQuery keydown() method trigger the keydown event. The jQuery keydown event occurs when a keyboard key is on way to press down. And when the keydown event occurs, specified function will execute.

Syntax

This triggers the keydown event on the selected elements.

$(selector).keydown();        // This syntax does not accept any arguments.

Attach a function to the keydown event.

$(selector).keydown(function);
Parameter Type Description
function Function Optional. Specifies the function to execute when the keydown event is occurs.

Examples

This example represents the keydown() event.

$(document).ready(function(){
  $("input").keydown(function(){
    $("input").css("background-color", "#FFFF99");
  });
  $("input").keyup(function(){
    $("input").css("background-color", "pink");
  });
  $("#btn1").click(function(){
    $("input").keydown();
  });  
  $("#btn2").click(function(){
    $("input").keyup();
  });
});

Run it...   »


This example represent to attach a function to the keydown() event.

$(document).ready(function(){
  $("input").keydown(function(){
    $(this).css("background-color", "#FFFF99");
  });
  $("input").keyup(function(){
    $(this).css("background-color", "pink");
  });
});

Run it...   »