Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to check which key has been pressed using jQuery?
To check which key has been pressed, use the onkeydown attribute.
Example
You can try to run the following code to get which key is pressed:
<!DOCTYPE html>
<html>
<body>
<p>Press a key in the below box to get which key is pressed.</p>
<input type="text" size="10" onkeydown="demoFunction(event)">
<p id="test"></p>
<script>
function demoFunction(event) {
var a = event.key;
document.getElementById("test").innerHTML = "You've pressed the key: " + a;
}
</script>
</body>
</html> Advertisements
