Created
July 4, 2012 07:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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