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.


$(selector).keypress() - Trigger the keypress event for the selected elements.

$(selector).keypress(function) - Attach a function to the keypress event.


	<!doctype html>
	<html lang="en">
			<meta charset="utf-8">

			<script src=""></script>
				i = 0;  
						$("span").text (i += 1);  
			Write something: <input type="text">  
			<p>Keypresses: <span>0</span></p>  

$("input").keypress(function(){ $("span").text (i += 1); it calculates how many times we press the key.