All you need to do is to change the type
property of the element from password
to text
back and forth:
<input
type="password"
class="input_password"
oninput="onPasswordChange(this)">
function togglePassword() {
const password = document.querySelector('.input_password');
if(password.type === 'password') {
password.type = 'text';
} else {
password.type = 'password';
}
}
References: