cybercode-ui-library/js/showPassword.js
2024-09-24 08:13:46 +07:00

20 lines
791 B
JavaScript

document.addEventListener('DOMContentLoaded', () => {
const targetEl = document.querySelector('.passwordVisibilityToggle')
targetEl.addEventListener('click', () => {
const parent = targetEl.parentNode
const childrenArr = Array.from(parent.children);
for (let item of childrenArr) {
if (item.localName === 'input') {
if (item.getAttribute('type') === 'password') {
targetEl.textContent = 'Скрыть пароль'
item.setAttribute('type', 'text');
} else {
item.setAttribute('type', 'password');
targetEl.textContent = 'Показать пароль'
}
return false;
}
}
})
})