Keyboard Events
The goal of this coding exam is to quickly get you off the ground with Keydown event
Use the below reference image
https://assets.ccbp.in/frontend/content/dynamic-webapps/keyboard-event-op.gif
Achieve the given functionality using JS
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Keyboard Events</h1>
<label>Enter the value: <input id="userInput" type="text"></label>
<p>keydown() fired: <span id="keydownCounter">0</span> times</p>
<p>Recent keyCode: <span id="keydownCode">0</span></p>
<script>
var keydownCounter = document.getElementById("keydownCounter");
var keydownCode = document.getElementById("keydownCode");
var userInput = document.getElementById("userInput");
userInput.addEventListener("keydown", function(event) {
keydownCounter.textContent++;
keydownCode.textContent = event.keyCode;
})
</script>
</body>
</html>
Comments
Leave a comment