How to check caps lock is on in javascript
How to check caps lock is on in javascript
Hello everyone, in this post we will examine how to solve the "How to check caps lock is on in javascript" programming puzzle.
You can check caps lock is on or not in javascript by using getModifierState() method on keyup event. It will display a message if the caps lock button is on using getModifierState() which returns true if the modifier is active and false if it is not active.-
Display message if caps lock is on in javascript
<input type="password" name="password" id="password" placeholder="Enter password"/> <div id="message"></div> <script> const password = document.querySelector('#password'); const message = document.querySelector('#message'); password.addEventListener('keyup', function (e) { if (e.getModifierState('CapsLock')) { message.textContent = 'Caps lock is on'; } else { message.textContent = ''; } }); </script>
This code snippet helps you to show the message if the caps lock button is on. Just copy/paste code in body tag of HTML page or you can use it as per your requirements and it will display message on click caps lock button if it is on.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Javascript
- How to use JavaScript to search for items in a list
- How to add a property to object with condition in javascript
- Get hostname from URL in javascript
- How to pass array as arguments to function in javascript
- Remove hostname from URL in javascript
- Get multiplication in javascript using array input
- Cropper js with multiple images
- How to add key/value pair to existing form data
- On click enter redirect to another URL with parameters in javascript
- Apex bar chart - fill bar color with gradient on hover
- How to echo array in Javascript
- Javascript to print Fibonacci series upto 15 Observations
- Trim the leading and trailing comma from string in Javascript
- How to preview video before uploading in javascript
- How to get query string value in javascript
- How to check file is an image in javascript using filename
- Uncaught SyntaxError: Identifier 'CODE' has already been declared
- How to preview a word document in HTML using javascript
- Hide div on click outside of element in javascript/jQuery
- How to display for slash as a string in javascript HTML
- Prism js horizontally overflowing its container
- Custom slider js
- Uncaught TypeError: $(...).summernote is not a function
- How to show and hide placeholder text
- Deault order of record in datatable