SyntaxStudy
Sign Up
jQuery Password Visibility Toggle
jQuery Beginner 3 min read

Password Visibility Toggle

Show/Hide Password

Toggle password field visibility with a button, switching between type="password" and type="text".

Example
$("#togglePass").on("click", function() {
  const input = $("#password");
  const isText = input.attr("type") === "text";
  input.attr("type", isText ? "password" : "text");
  $(this).html(isText ? "Show" : "Hide");
});
Pro Tip

Use an eye icon instead of text for a cleaner UI — toggle between bi-eye and bi-eye-slash.