Skip to content

Instantly share code, notes, and snippets.

@dkrnl
Created May 7, 2015 03:59
Show Gist options
  • Save dkrnl/9fdd1a93c9a83e889098 to your computer and use it in GitHub Desktop.
Save dkrnl/9fdd1a93c9a83e889098 to your computer and use it in GitHub Desktop.
Input Password Type Toggle
<div class="input-group">
<input class="form-control" id="id_password" name="password" required="required" type="password" value="" />
<label class="input-group-addon" for="id_password" id="id_password_toggle">
<i class="fa fa-eye-slash"></i>
</label>
</div>
<script>
jQuery(function($) {
var input = $("#id_password");
$("#id_password_toggle").on("mousedown", function() {
input.attr("type", "text");
$(".fa", this).attr("class", "fa fa-eye");
}).on("mouseup mouseleave", function() {
input.attr("type", "password");
$(".fa", this).attr("class", "fa fa-eye-slash");
}).attr("unselectable", "on").css("user-select", "none").on("selectstart", false);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment