Created
October 22, 2019 11:18
-
-
Save savicas/3c35eccc6c79f395235bd9b3133444e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Listen for changes on the entire window | |
window.addEventListener('change', function (event) { | |
// matches polyfill | |
if (!Element.prototype.matches) { | |
Element.prototype.matches = Element.prototype.msMatchesSelector ||Element.prototype.webkitMatchesSelector; | |
} | |
if (event.target.matches('[type=checkbox]')) { | |
const showOnePwd = document.querySelector('#password'); | |
const nodeForms = Array.prototype.slice.call(document.querySelectorAll('form')); | |
const showMultiplePwd = Array.prototype.slice.call(nodeForms[1].querySelectorAll('[type=password]')); | |
const checkbox1 = nodeForms[0].querySelector('[type=checkbox]'); | |
const checkbox2 = nodeForms[1].querySelector('[type=checkbox]'); | |
// console.log(showOnePwd); | |
// console.log(nodeForms); | |
// console.log(showMultiplePwd); | |
// console.log(checkbox1.checked); | |
// console.log(checkbox2); | |
if (checkbox1.checked) { | |
showOnePwd.type = 'text'; | |
} else { | |
showOnePwd.type = 'password'; | |
console.log('You have no password written'); | |
} | |
if (checkbox2.checked) { | |
showMultiplePwd.forEach(function(eachNode, i){ | |
eachNode.setAttribute('type', 'text'); | |
}); | |
} else { | |
showMultiplePwd.forEach(function(eachNode, i){ | |
eachNode.setAttribute('type', 'password'); | |
}); | |
} | |
} | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment