Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM KeyboardEvent altKey Property
The HTML DOM KeyboardEvent altKey property returns whether an ALT key was pressed or not when a key event was triggered in an HTML document.
Syntax
Following is the syntax −
event.altKey
Let us see an example of HTML KeyboardEvent altKey property−
Example
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
text-align: center;
}
input {
border: 2px solid #fff;
padding: 8px;
background: transparent;
width: 310px;
border-radius: 20px;
outline: none;
}
::placeholder {
color: #000;
}
.show {
font-size: 1.2rem;
color: #fff;
}
</style>
<body>
<h1>HTML KeyboardEvent altKey Property Demo</h1>
<input type="text" placeholder="Enter your message" onkeydown="display(event)">
<div class="show">
</div>
<script>
function display(event) {
if (event.altKey) {
document.querySelector(".show").innerHTML = "The key is " + event.key + " key";
} else {
document.querySelector(".show").innerHTML = "The key is " + event.key + " key";
}
}
</script>
</body>
</html>
Output

Now start pressing any key in the text field and then observe when an ALT key is pressed how altKey property works−

Advertisements