diff --git a/js-essentials/toggle-multiple-forms/index.html b/js-essentials/toggle-multiple-forms/index.html index c49805c..2ee8326 100644 --- a/js-essentials/toggle-multiple-forms/index.html +++ b/js-essentials/toggle-multiple-forms/index.html @@ -19,12 +19,12 @@
- +
@@ -40,12 +40,12 @@
- +
- +
diff --git a/js-essentials/toggle-multiple-forms/script.js b/js-essentials/toggle-multiple-forms/script.js index fd2acf9..8a65706 100644 --- a/js-essentials/toggle-multiple-forms/script.js +++ b/js-essentials/toggle-multiple-forms/script.js @@ -1,19 +1,13 @@ -let passwordFields = document.querySelectorAll('input[type="password"]'); -let checkboxes = document.querySelectorAll('input[type="checkbox"]'); let state = {true: "text", false: "password" }; window.addEventListener('click', function (event) { - if (event.target.matches('#show-password')) { + if (event.target.matches('input[type="checkbox"]')) { + let checkbox = event.target; + let passwordFields = checkbox.form.querySelectorAll('.password'); + for (let field of passwordFields) { - field.type=state[event.target.checked]; + field.type=state[checkbox.checked]; } } - else { - console.log("Show passwords toggle"); - for (let field of passwordFields) { - field.type=state[event.target.checked]; - } - } - });