Skip to content

Instantly share code, notes, and snippets.

@SindhujaD
Created January 6, 2014 00:10
Show Gist options
  • Select an option

  • Save SindhujaD/8276007 to your computer and use it in GitHub Desktop.

Select an option

Save SindhujaD/8276007 to your computer and use it in GitHub Desktop.
A Pen by Jeplaa.
<h1>Show / Hide password using <a href="http://jquery.com/">jQuery</a></h1>
<div id="content">
<input type="password" id="password">
<button id="button" title="Hold down to show password"></button>
</div>
// ADDED:
// - Mobile Devices support (tested on iPad)
// TODO:
// - Suggestions are welcome...
$(document).ready(function()
{
$('#password').val('Example Password');
var password = $('#password');
var button = $('#button');
button.mousedown(function()
{
password.attr('type', 'text');
});
button.mouseup(function()
{
password.attr('type', 'password');
});
button.mouseleave(function()
{
password.attr('type', 'password');
});
if(navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i))
{
//alert('Mobile device detected!');
button.on("touchstart", function()
{
password.attr('type', 'text');
});
button.on("touchend", function()
{
password.attr('type', 'password');
});
}
});

Show / Hide password

Show / Hide password using jQuery

Suggestions are welcome.

A Pen by Jeplaa on CodePen.

License.

@import url('http://fonts.googleapis.com/css?family=Open+Sans:400,300');
* { margin: 0px; padding: 0px; }
body
{
background-color: #384047;
width: 100%;
height: 100%;
margin: 0px;
}
h1
{
color: #888;
font-family: 'Open Sans', Helvetica, Arial, sans-serif;
font-size: 40px;
margin-top: 30px;
text-align: center;
}
h1 a { color: #0769AD; text-decoration: none; }
#content
{
position: relative;
top: 50px;
width: 400px;
margin: 0px auto;
}
#password
{
color: #888;
font-size: 20px;
width: 400px;
margin: 0px auto;
padding: 15px;
background-color: rgba(255, 255, 255, 0.1);
box-shadow: 0 0 50px 0 rgba(0, 0, 0, .25);
border: 1px solid rgba(255, 255, 255, 0.2);
outline: none;
}
#password:focus { color: #FFF; }
#button
{
position: relative;
float: right;
right: -30px;
bottom: 50px;
background: url(http://www.jqueryscript.net/demo/Toggle-Password-Visibility-With-jQuery-hideShowPassword/img/wink.svg) no-repeat;
width: 50px;
height: 50px;
border: none;
outline: none;
cursor: pointer;
background-position: 0px 0px;
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
-moz-tap-highlight-color: rgba(255, 255, 255, 0);
-o-tap-highlight-color: rgba(255, 255, 255, 0);
tap-highlight-color: rgba(255, 255, 255, 0);
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-o-user-select: none;
user-select: none;
}
#button:active { background-position: -44px 0px; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment