Skip to content

Instantly share code, notes, and snippets.

@cesjam7
Created January 16, 2022 06:01
Show Gist options
  • Save cesjam7/d3717cc8055aa2a988a4bd954b6beb29 to your computer and use it in GitHub Desktop.
Save cesjam7/d3717cc8055aa2a988a4bd954b6beb29 to your computer and use it in GitHub Desktop.
Ocultar y mostrar contraseña
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="contrasena">
<input type="password" id="contrasena">
<i class="fa fa-eye" id="mostrar"></i>
</div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script>
$(function($) {
$('#mostrar').click(function() {
if ($(this).hasClass('fa-eye')) {
$('#contrasena').attr('type', 'text');
$('#mostrar').attr('class', 'fa fa-eye-slash');
} else {
$('#contrasena').attr('type', 'password');
$('#mostrar').attr('class', 'fa fa-eye');
}
})
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment