Place a button after an input and show it's password in plain text
You can first create the i element and add a click event handler to it dynamically while you wrap it inside the div and span and add it to the document.

As you use jQuery, I would suggest using it for creating each individual element, providing it with attributes using jQuery methods. 

Here is how you could do it:



function togglePasswordVisibility($pw, on, $eye) {
    $pw.attr('type', on ? 'password' : 'text');
    $eye.toggleClass('fa-eye-slash fa-eye');
}

$("[type=password]").each(function () {
    var $pw = $(this);
    var $eye = $("&lt;i&gt;").addClass("fas fa-eye-slash").click(function () {
        togglePasswordVisibility($pw, false, $eye);
        setTimeout(function() {
            togglePasswordVisibility($pw, true, $eye);
        }, 800);
    });
    $pw.parent().append(
        $("&lt;div&gt;").addClass("input-group-append").append(
            $("&lt;span&gt;").addClass("password-button password-button-main").append($eye)
        )
    );
});
&lt;link href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" rel="stylesheet"/&gt;
&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;

&lt;link href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" rel="stylesheet"/&gt;

&lt;div class="input-group"&gt;
    &lt;input type="password" id="pass-on" title="&lt;?php echo $user-&gt;valid_password_error; ?&gt;" class="form-control" name="txt_upass" placeholder="Enter Password" autocomplete="off" value="" oninvalid="setCustomValidity('&lt;?php echo $user-&gt;password_error; ?&gt;')" oninput="setCustomValidity('')" required /&gt;
    &lt;label for="pass-on"&gt;Password&lt;/label&gt;
&lt;/div&gt;
                
&lt;div class="form-group input-group"&gt;
    &lt;input type="password" id="pass-verify-on" title="&lt;?php echo $user-&gt;valid_password_error; ?&gt;" class="form-control" name="txt_upass_ok" placeholder="Retype Password" autocomplete="off" value="" oninvalid="setCustomValidity('&lt;?php echo $user-&gt;password_error; ?&gt;')" oninput="setCustomValidity('')" required /&gt;
    &lt;label for="pass-verify-on"&gt;Retype Password&lt;/label&gt;
&lt;/div&gt;