jQuery Examples - keypress( )



Description

The keypress() method triggers the keypress event of each matched element.

Syntax

Here is the simple syntax to use this method −

selector.keypress()

Parameters

None

Example

Following is a simple example showing the usage of this method. Here it triggers the keypress event of each matched element −

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
   </head>	

   <body>			
      <form name = "sampleForm">
         <label>Enter Name: </label><input type = "text" id = "result1" title="Enter Name" value = "" ></input><br/><br/>         
         <input type = "button" value = "Trigger KeyPress" onclick="triggerKeyPress();"/>
      </form>		
      <script type = "text/javascript" language = "javascript">
         function triggerKeyPress(){		   
            $("#result1").keypress();
         }

         $("#result1").keypress(function( event ) {
            alert("Handler for keypress() called!");
         });
      </script>
   </body>	
</html>

This will produce following result −

jqueryexamples_events.htm
Advertisements