Keypress

[medical] key (computer virus name)

jquery keypress() method syntax

Function: The keypress event is similar to the keydown event. This event occurs when the button is pressed. It happens on the element that currently has focus. However, unlike the keydown event, the keypress event occurs every time a character is inserted. The keypress() method triggers the keypress event, or specifies a function to run when the keypress event occurs. If set on a document element, this event occurs regardless of whether the element has focus.

Trigger the keypress event syntax: $(selector).keypress()

Bind the function to the keypress event syntax: $ (selector).keypress(function)

Parameters:

ParametersDescription
function Optional. Specifies the function to be run when the keypress event occurs.

jquery keypress() method example

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
i=0;
$(document).ready(function(){
  $("input").keypress(function(){
    $("span").text(i+=1);
  });
});
</script>
</head>
<body>
Enter your name: <input type="text" />
<p>Keypresses:<span>0</span></p>
</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance