Skip to content

Instantly share code, notes, and snippets.

@Takaya213
Created May 2, 2013 07:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Takaya213/5500774 to your computer and use it in GitHub Desktop.
Save Takaya213/5500774 to your computer and use it in GitHub Desktop.
A jQuery method to show and hide passwords in forms.
$(document).ready(function(){
$('.showpassword').each(function (index, input){
var $input = $(input);
$("#passwordshow").click(function () {
var change = $(this).is(":checked") ? "text" : "password";
var text = $(this).is(":checked") ? "Hide Password" : "Show Password";
var rep = $("<input type='" + change + "' />")
.attr("id", $input.attr("id"))
.attr("name", $input.attr("name"))
.attr('class', $input.attr('class'))
.val($input.val())
.insertBefore($input);
$input.remove();
$input = rep;
$('label[for="passwordshow"]').html(text);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment