Show password

https://www.drupal.org/node/2293803

by corbacho

HTML

<div class="form-type-password"><input type="password"></input></div>

<br>
    
<div class="form-type-password"><input type="password"></input></div>

JavaScript

$(':password').each(function(){
        // Create the toggle button.
        var showPassword = $('<button data-show-password-trigger data-state="hidden" class="link">' + 'Show password' + '</button>');
        // Add it next to the password field
        showPassword.insertAfter(this);
        // Add click handler to the toggle.
        showPassword.on('click.show-password', function (e) {
          e.preventDefault();
          if ($(this).data('state') === 'hidden') {
            // Switch password input type to text.
            $(this).closest('.form-type-password').find(':password').attr('type', 'text');
            $(this).text('Hide password');
            $(this).data('state','shown');
          }
          else {
            // Switch the input type back to password.
            $(this).closest('.form-type-password').find(':text').attr('type', 'password');
            $(this).text('Show password');
            $(this).data('state','hidden');
          }
         });
});