0

The first time toggle-password is working fine, but when I click on 'edit model' the model will open. After closing the model the toggle-password in the table is not working. I don't why it is not working. Can anyone please help me.

$(".toggle-password").click(function() {
  $(this).toggleClass("fa-eye fa-eye-slash");
  var input = $($(this).attr("toggle"));
  if (input.attr("type") == "password") {
    alert('test');
    input.attr("type", "text");
  } else {
    input.attr("type", "password");
  }
});
<td>
  <?php
    if($auth_details['auth_key'] != "")
    {
      $r_id = $auth_details['id'];
      $ak = $auth_details['auth_key'];
      echo "<div class='form-group'>
          <div class='row'>
            <div class='col-md-12'>
              <div class='input-group'>
                <input class='form-control' id='auth_keyt_".$r_id."' value='".$ak."' name='auth_keyt_".$r_id."' type='password' required autocomplete='off' style='border:none;'/>
                <div class='input-group-addon' style='background:none;border:none;'>
                  <span toggle='#auth_keyt_".$r_id."' class='fa fa-fw fa-eye field-icon toggle-password'></span>
                </div>
              </div>
            </div>
          </div>
        </div>";
    }
    else 
    {
      echo '';
    }
  ?>
</td>
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339

1 Answers1

0

Update your code as like following. This will to trigger events for asynchronous elements.

$(document).on("click", ".toggle-password", function() { 
    $(this).toggleClass("fa-eye fa-eye-slash");
    var input = $($(this).attr("toggle"));
    if (input.attr("type") == "password") {alert('test');
        input.attr("type", "text");
    } 
    else {
        input.attr("type", "password");
    }
});
Mohammedshafeek C S
  • 1,916
  • 2
  • 16
  • 26