function togglePassword() { $(".passwords").each(function() { if ($(this).attr('type') === "password") { $(this).attr('type', 'text'); } else { $(this).attr('type', 'password'); } }); } //checkbox <div class="form-check"> <input class="form-check-input" type="checkbox" value="" id="showPassword" onclick="togglePassword()"> <label class="custom-control-label" for="customCheck1">Show Passwords</label> </div>