-
keydown( ) returns jQuery
Triggers the keydown event of each matched element.
This causes all of the functions that have been bound to the keydown event to be executed, and calls the browser's default keydown action on the matching element(s). This default action can be prevented by returning false from one of the functions bound to the keydown event. The keydown event usually fires when a key on the keyboard is pressed. -
keydown( Function fn ) returns jQuery
Bind a function to the keydown event of each matched element.
The keydown event fires when a key on the keyboard is pressed.Example:
To perform actions in response to keyboard presses on a page, try:
$(window).keydown(function(event){ switch (event.keyCode) { // ... // different keys do different things // Different browsers provide different codes // see here for details: http://unixpapa.com/js/key.html // ... } }); -
keypress( ) returns jQuery
Triggers the keypress event of each matched element.
This causes all of the functions that have been bound to the keypress event to be executed, and calls the browser's default keypress action on the matching element(s). This default action can be prevented by returning false from one of the functions bound to the keypress event. The keypress event usually fires when a key on the keyboard is pressed.
-
keypress( Function fn ) returns jQuery
Binds a function to the keypress event of each matched element.
The keypress event fires when a key on the keyboard is "clicked". A keypress is defined as a keydown and keyup on the same key. The sequence of these events is: <ul><li>keydown</li><li>keyup</li><li>keypress</li></ul>Example:
Show spaces and letters when typed.
$("input").keypress(function (e) { if (e.which == 32 || (65 <= e.which && e.which <= 65 + 25) || (97 <= e.which && e.which <= 97 + 25)) { var c = String.fromCharCode(e.which); $("p").append($("<span/>")) .children(":last") .append(document.createTextNode(c)); } else if (e.which == 8) { // backspace in IE only be on keydown $("p").children(":last").remove(); } $("div").text(e.which); });HTML:
<input type="text" /> <p>Add text - </p> <div></div> -
keyup( ) returns jQuery
Triggers the keyup event of each matched element.
This causes all of the functions that have been bound to the keyup event to be executed, and calls the browser's default keyup action on the matching element(s). This default action can be prevented by returning false from one of the functions bound to the keyup event. The keyup event usually fires when a key on the keyboard is released. -
keyup( Function fn ) returns jQuery
Bind a function to the keyup event of each matched element.
The keyup event fires when a key on the keyboard is released.Example:
To perform an action when the escape key has been released:
$(document).keyup(function(event){ if (event.keyCode == 27) { alert('escaped!'); } });