79656393

Date: 2025-06-06 19:37:58
Score: 0.5
Natty:
Report link

Revise your toggle code to clearly include or exclude classes according to the existing state:

document.querySelectorAll('.toggle-password').forEach(icon => {
  icon.addEventListener('click', () => {
    const targetId = icon.getAttribute('data-target');
    const input = document.getElementById(targetId);
    if (!input) return;

    const isHidden = input.type === 'password';
    input.type = isHidden ? 'text' : 'password';

    // Update icon classes explicitly
    if (isHidden) {
      // Show as slashed eye
      icon.classList.remove('fa-eye');
      icon.classList.add('fa-eye-slash');
    } else {
      // Show as eye
      icon.classList.remove('fa-eye-slash');
      icon.classList.add('fa-eye');
    }
  });
});
                

Working codepen

Reasons:
  • Contains signature (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Adil