I am trying to have a checkbox on a page to show/hide passwords in password boxes. If they are hidden, then they will instead show on hover of that item.
The only thing I am struggling with is that the var is saved on page load along with when the rest of the jquery loads. How can I, on every mouseenter/leave, make sure that the checkbox is checked or not?
window.hide_passwords = $('#hide_passwords').attr('checked');
if(hide_passwords) {
$("main table tbody tr").on({
mouseenter: function() {
$(this).children('td:first-child').children('input').attr('type', 'text');
},
mouseleave: function() {
$(this).children('td:first-child').children('input').attr('type', 'password');
}
});
} else {
$('input[type="password"]').attr('type', 'text');
}
$('#hide_passwords').click(function() {
if($(this).prop('checked')) {
window.hide_passwords = false;
} else {
window.hide_passwords = true;
}
});