seularts 0 Light Poster

I have managed to achieve this action through this:

<link href="" rel="stylesheet"/>
<script src=""></script>

<div class="input-group">
                    <input type="password" id="pass-on" title="<?php echo $user->valid_password_error; ?>" class="form-control" name="txt_upass" placeholder="Enter Password" autocomplete="off" value="" oninvalid="setCustomValidity('<?php echo $user->password_error; ?>')" oninput="setCustomValidity('')" required />
                    <div class="input-group-append">
                        <span class="password-button password-button-main" data-id="pass-on"><i class="fas fa-eye-slash"></i></span>
                <div class="form-group progress jquery-result-1" style="height: 10px;">

                    <div class="form-group input-group">
                        <input type="password" id="pass-verify-on" title="<?php echo $user->valid_password_error; ?>" class="form-control" name="txt_upass_ok" placeholder="Retype Password" autocomplete="off" value="" oninvalid="setCustomValidity('<?php echo $user->password_error; ?>')" oninput="setCustomValidity('')" required />
                        <label>Retype Password</label>
                        <div class="input-group-append">
                            <span class="password-button password-button-verify" data-id="pass-verify-on"><i class="fas fa-eye-slash"></i></span>

                        function togglePasswordVisibility($pw, on, id) {
        $pw.attr('type', on ? 'password' : 'text');
        $('[data-id=' + id + '] > i').toggleClass('fa-eye-slash fa-eye');

    // $("#pass-on").after('<div class="input-group-append"><span class="password-button password-button-main"><i class="fas fa-eye-slash"></i></span></div>');

    $('[data-id]').on('click', function() {
        var id = $(this).data('id'),
            $pw = $('#' + id);

        togglePasswordVisibility($pw, false, id);

        setTimeout(function() {
            togglePasswordVisibility($pw, true, id);
        }, 800);

But I would like to place the password button from within the function using the commented line with the after callback and making it apply the same effect. Right now the button correlates with the input through the association of data-id and id. If I would to place it inside the function I would have to get rid of the data-id and still make it act individually on each input, I just can't figure how. Thank you for your time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.