function getPassword($container, password) { $container.data('password', password); $container.find('span').html(password); $container.find('a').detach(); $container.prepend(''); } function hidePassword($src){ $src.siblings('span').html('********'); $src.removeClass('fa-unlock').addClass('fa-lock'); } function revealPassword($src){ $src.siblings('span').html($src.parent().data('password')); $src.removeClass('fa-lock').addClass('fa-unlock'); } $(function(){ $("[data-id=passwd]").on("ajax:success", "a", function(e, data){ getPassword($(e.target).parent(), data.hash); }); $("[data-id=passwd]").on('click', 'i', function(){ if($(this).hasClass('fa-unlock')){ hidePassword($(this)); } else { revealPassword($(this)); } }); });