// Get references to the password input and toggle button
const passwordInput = document.getElementById('passwordInput');
const toggleButton = document.getElementById('toggleButton');
// Add event listener to the toggle button
toggleButton.addEventListener('click', () => {
// Toggle the password input type between 'password' and 'text'
passwordInput.type = passwordInput.type === 'password' ? 'text' : 'password';
});
code
Password Toggle
This JavaScript code provides a simple password toggle functionality. It toggles the visibility of the password input by changing its type attribute between 'password' and 'text' when the toggle button is clicked.
Event Listener
DOM Manipulation