const password = document.querySelector("#password"); const eyeIcon = document.querySelector("#eye"); eyeIcon.addEventListener("click", () => { if (eyeIcon.classList.contains("fa-eye")) { password.setAttribute("type", "text"); eyeIcon.classList.replace("fa-eye", "fa-eye-slash"); } else { password.setAttribute("type", "password"); eyeIcon.classList.replace("fa-eye-slash", "fa-eye"); } });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter