Created
September 11, 2017 21:49
-
-
Save ilmoralito/c5cda7fc9efe0f3aee8feb4f1b7c2fe7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Having this or similar html | |
<input type="password" name="password" id="password"> | |
<button id="toggleButton">Show password</button | |
// And wanting to display the password when mousedown and hide the password when mouseup or mouseleave | |
// In a similar way as is done in the firefox async login form | |
// If you are in firefox you can go to this url: about:accounts?action=signin&entrypoint=menupanel | |
const password = document.querySelector('#password'); | |
const toggleButton = document.querySelector('#toggleButton'); | |
toggleButton.addEventListener('mousedown', displayPassword); | |
toggleButton.addEventListener('mouseup', hidePassword); | |
toggleButton.addEventListener('mouseleave', hidePassword); | |
function displayPassword() { | |
password.setAttribute('type', 'text'); | |
} | |
function hidePassword() { | |
password.setAttribute('type', 'password'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment