document.querySelectorAll('[data-dc-pw]').forEach(function (btn) {
btn.addEventListener('click', function () {
var input = document.getElementById(btn.getAttribute('data-dc-pw'));
if (!input) return;
var show = input.type === 'password';
input.type = show ? 'text' : 'password';
btn.setAttribute('aria-pressed', show ? 'true' : 'false');
var name = btn.querySelector('.dc-sr');
if (name) name.textContent = show ? '비밀번호 숨기기' : '비밀번호 보기';
input.focus();
});
});
How to use it
Let the reveal toggle report its state with aria-pressed, and swap its label between show and hide
Put the rules in front of people before they type, not after they fail
Prefer one reveal toggle over asking for the password twice
Watch out for
Keep the cursor in the field after the toggle is pressed — don't make anyone click back in
A strength meter needs a word like "strong" beside the bars; color alone is not a reading