keypress()
method
The keypress() method triggers the keypress event, or
attaches a function to run when a keypress event occurs.The keypress event is
similar to the keydown event. The event occurs when a button is pressed
down.However, the keypress event is not fired for all keys (e.g. ALT, CTRL,
SHIFT, ESC). Use the keydown() method to also check these keys.
The order of events related to the keypress event:
·
keydown - The key is on its way down
·
keypress - The key is pressed down
·
keyup - The key is released
|
Syntex:-
$(selector).keypress()
|
Example :-
<!DOCTYPE
html>
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
i =
0;
$(document).ready(function(){
$("input").keypress(function(){
$("span").text(i += 1);
});
});
</script>
</head>
<body>
Enter
something inside textbox: <input type="text">
<p>Keypresses
count: <span>0</span></p>
</body>
</html>
|