Skip to content

Instantly share code, notes, and snippets.

@roine
Created July 4, 2012 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roine/3045845 to your computer and use it in GitHub Desktop.
Save roine/3045845 to your computer and use it in GitHub Desktop.
auto add checkbox after input type password, checking it allow to see the content
var reveal = function(msgIn, msgOut){
msgIn = msgIn || "Reveal it!";
msgOut = msgOut || "Hide It!";
$("input[type=password]").each(function(){
var self = $(this);
$(this).after("<span id='revealctrl'></span>")
.next()
.append("<input type=checkbox id='revealCheckbox'>")
.append("<span id='revealMessage'>"+msgIn+"<span>")
.find("#revealCheckbox")
.click(function(){
if($(this).attr('checked')){
self[0].type = "text";
msg = msgOut;
}
else{
self[0].type = "password";
msg = msgIn;
}
msg = "<span id='revealMessage'>"+msg+"</span>";
$(this).next().remove().end().after(msg);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment