🍦 Vanilla JavaScript

Projects for the Vanilla JS Academy

Day 3

Toggle Multiple Password Fields

Goal

Modify the previous script, adding the ability to toggle the visibility of multiple fields.

Project

View Source
(function() {
	let elPasswords = document.querySelectorAll( "input[type='password']" );
	let elShowPasswords = document.querySelector( "#show-passwords" );
	elShowPasswords.addEventListener( "input", e =>
	{
		let inputType = e.target.checked ? "text" : "password";
		elPasswords.forEach( elPassword => elPassword.setAttribute( "type", inputType ) );
	});
})();