<input type="password" id="password">
<button onclick="switchVisibility()">show / hide</button>
const passwordField = document.querySelector('#password')
function switchVisibility() {
if (passwordField.getAttribute('type') === 'password') passwordField.setAttribute('type', 'text')
else passwordField.setAttribute('type', 'password')
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.