-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
28 lines (23 loc) · 848 Bytes
/
script.js
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
27
28
const inputs = document.querySelectorAll('.input');
const button = document.querySelector('.login__button');
const handleFocus = ({ target }) => {
const span = target.previousElementSibling;
span.classList.add('span-active');
}
const handleFocusOut = ({ target }) => {
if (target.value === '') {
const span = target.previousElementSibling;
span.classList.remove('span-active');
}
}
const handleChange = () => {
const [username, password] = inputs;
if (username.value && password.value.length >= 8) {
button.removeAttribute('disabled');
} else {
button.setAttribute('disabled', '');
}
}
inputs.forEach((input) => input.addEventListener('focus', handleFocus));
inputs.forEach((input) => input.addEventListener('focusout', handleFocusOut));
inputs.forEach((input) => input.addEventListener('input', handleChange));