JSFiddle - React, Tailwind, and code Playground

by blineberry

HTML

<label for="password">Password: </label>
<input name="password" type="password" />

JavaScript

$('input[type="password"]').each(function() {
    var input = $(this);
    var button = $('<button />', { 
        type: 'button', 
        text: 'Show' 
    }).insertAfter(input)
    .on('click', function() {
        if (input.attr('type') === 'password') {
            input.attr('type','text');
            button.text('Hide');
        }
        else {
            input.attr('type','password');
            button.text('Show');
        }
    });
    
    button.triggerHandler('click');
});