Today, I learned how to create a 'Display Password' utility. I learnt how to attach event listeners on click of HTML elements like buttons and checkboxes. Thanks to Chris Ferdinandi from GoMakeThings. for showing how to do it.
const passwordBtn = document.getElementById('singlePassword');
const passwordDisplay = document.getElementById('password');
passwordBtn.addEventListener('click', function () {
if (passwordBtn.checked) {
passwordDisplay.type = 'text';
} else {
passwordDisplay.type = 'password';
}
});
Category | HTML / JS / CSS |
Credits | Chris Ferdinandi |
Date | February 1st, 2025 |
Codepen | NA |