LearnFast.Ninja

jQuery keypress codes view at console the key events code

When the DOM is fully loaded execute anonymous function that execute another function that write the keyCode of the key you press down to the console. Note: You can use the following events. Note: You can also use alert for debugging. See the working example and test the result.

Step 1: When the DOM is fully loaded execute anonymous function that execute another function that write 
the keyCode of the key you press down to the console. 

$(document).ready(function () {

    $(document).keydown(function (event) {

        console.log('event.keyCode: ' + event.keyCode);

    });

});

 
Note: You can use the following events: 

$(document).keydown

$(document).keypress

$(document).keyup

 
Note: You can also use alert for debugging: 

alert('event.keyCode: ' + event.keyCode);

 
 
Working Example: 

<html>

<head>

    <title></title>

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.js"></script>

    <script type="text/javascript">

        $(document).ready(function () {

            $(document).keydown(function (event) {

                console.log('event.keyCode: ' + event.keyCode);

            });

        });

    </script>

</head>

<body>

</body>

</html>

 
Result: (Press some key…) 


Tags

jquery

events