-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathindex.js
More file actions
26 lines (23 loc) · 1.05 KB
/
index.js
File metadata and controls
26 lines (23 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// ✅ this will work, acquire input node once script is loading, and the reference is not change even node attribute change
// const input_password = document.querySelector(`input[type="password"]`);
function toggleShowHide() {
// ✅ Acquire input node with id name, this works since id is fixed
const input_password = document.getElementById(`inp_pw`);
// ⛔ reference DOM node every click using type attribute will NOT work, as type will change after clicking
// const input_password = document.querySelector(`input[type="password"]`);
// Acquire the eye icon
const eyeIcon = document.getElementsByClassName("fa-regular")[0];
if (input_password.type === "password") {
input_password.type = "text";
input_password.focus();
//toggle between "fa-eye-slash" & "fa-eye" class
eyeIcon.classList.remove("fa-eye");
eyeIcon.classList.add("fa-eye-slash");
} else {
input_password.type = "password";
input_password.focus();
//toggle between "fa-eye-slash" & "fa-eye" class
eyeIcon.classList.remove("fa-eye-slash");
eyeIcon.classList.add("fa-eye");
}
}