JSFiddle - React, Tailwind, and code Playground
by suaron
HTML
<div class="toggle-pass">
<input type="password" name="zpass" />
<a>Show</a>
</div>
CSS
.toggle-pass {
position: relative;
display: inline-block;
}
.toggle-pass > input {
padding: 8px 42px 8px 8px;
width: 250px;
border: 1px solid #ccc;
}
.toggle-pass > a {
position: absolute;
top: 0;
right: 0px;
padding: 6px 8px;
font-size: .85em;
color: #a5a5a5;
background: #eee;
border: 1px solid #ccc;
border-left: 0;
text-decoration: none;
cursor: pointer;
text-align: center;
width: 33px;
}
.toggle-pass > a:hover {
background-color: #ccc;
}
JavaScript
$(document).ready(function(){
$(".toggle-pass").each(function(){
var passbox = $("input", this)[0];
$("a", this).click(function(){
if(passbox.type == "password"){
passbox.type = "text";
this.innerHTML = "Hide";
} else {
passbox.type = "password";
this.innerHTML = "Show";
}
});
});
});