
Skip to main content
How to check caps lock is on in javascript
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.
Bootstrap
Cmd
CodeIgniter
Css
Drupal
Git
Html
Javascript
Jquery
Laravel
Nodejs
Php
Python
Sql
Typescript
Wordpress
Random Code Snippet Queries: Javascript
- Short-circuits conditionals
- JavaScript test() Method
- Get hostname from URL in javascript
- Uncaught TypeError: $(...).summernote is not a function
- How to display for slash as a string in javascript HTML
- How to remove duplicate values from array in javascript
- Uncaught TypeError: Cannot read property 'addEventListener' of undefined
- Uncaught TypeError: Illegal invocation
- Concat variable with string in javascript
- How to make entire Div clickable in javascript
- ReferenceError: $ is not defined
- How to add key/value pair to existing form data
- How to get the length of a number in JavaScript
- Animating numbers counting Javascript
- How to set href value of anchor tag in javascript
- How to pass array as arguments to function in javascript
- How to preview video before uploading in javascript
- How to show and hide placeholder text
- Remove hostname from URL in javascript
- On click enter redirect to another URL with parameters in javascript
- How to get file extension using javascript/jquery
- Prism js horizontally overflowing its container
- How to get query string value in javascript
- How to open modal after redirect
- Uncaught TypeError: Assignment to constant variable