Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Reveal Password Demo</title>
</head>
<body>
  <label>Password:
    <input id="pwd" type="password" role="password"
           aria-label="password"/> 
  </label>
  <button id="pwd-button" aria-controls="pwd">
    Show password text</button>
</body>
</html>
 
var pwdButton = document.getElementById("pwd-button");
var pwdInput = document.getElementById("pwd");
pwdButton.addEventListener("click", togglePasswordVisibility);
function togglePasswordVisibility(e){
  var hidden = (pwd.type === "password"); 
      //fetch current state
  
  hidden = !hidden; //toggle
  
  pwdButton.textContent = hidden?
    "Show password text" :
    "Hide password text" ;
  pwdInput.type = hidden?
    "password" :
    "text" ;
  pwdInput.setAttribute("aria-label", hidden?
    "Password" :
    "Password (shown)"
                       );
  
}
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers