I am currently working on implementing a TypeScript function in my webpage to enable the toggling of password visibility using an icon. The desired functionality is as follows: when a button (in this case, a clickable icon) is pressed, the icon should change and the input field's type property should switch to "text" to display the entered password. Pressing the button again should revert the icon to its default state and change the input type back to "password".
Here is the code I have written:
togglePasswordVisibility() {
document.querySelector("#input2").setAttribute("type", "password");
document.querySelector("#passwordIcon").setAttribute("name", "eye-off");
if (document.querySelector('#passwordIcon').getAttribute('name') == 'eye-off') {
document.querySelector('#passwordIcon').setAttribute("name", "eye");
}
}
The issue I am facing is that this implementation only works once, but I need it to be able to toggle password visibility multiple times. Any assistance would be greatly appreciated!