I'm trying to make a button to reveal the password written on the input. My poor JS skills tell me that I can achieve it by doing something like this:
I tried this:
$('#passReveal').on('click', function(){
$( "#input-show" ).attr('type', 'text');
if ($( "#input-show" ).attr('type', 'text')){
$( "#input-show" ).attr('type', 'password');
}
});
But doesn't work.
I think this one is the closest, but I have a bug: you must click twice the button to make it work the first time, why is that?
$('#passReveal').on('click', function(){
$( "#input-show" ).attr('type', 'text');
$( "#input-show" ).toggleClass('passRevealed');
if ($( "#input-show" ).hasClass('passRevealed')){
$( "#input-show" ).attr('type', 'password');
}
});
https://jsfiddle.net/tepLkc7u/2/
I hope you understand my bad english, im learning :)