Suchy Posted May 24, 2012 Share Posted May 24, 2012 Hi guys I am having a problem with jQuery + Ajax. When a user tries to registers (a new account) + enters a username that is in MySQL + a wrong password (associated with that username), he gets this message $('#pass-reminder').click(function() { alert('Password reminder'); return false; }); ... $.ajax ({ type: "POST", url: "register.php", data: input_data, success: function(return_data) ... if(return_data == 0) { $("#submited .message").html('Our record indicate that you already have an account.<br> If you forgotten your password<span class="link"><a id="pass-reminder" href="#"> click here</a></span>'); } ... } }); For some reason the function does not get called when I click on the link, but when I place the link (<a id="pass-reminder" href="#"> click here</a></span>) anywhere on the page it works. Any workaround this ? Quote Link to comment https://forums.phpfreaks.com/topic/263025-link-in-ajax-return/ Share on other sites More sharing options...
smoseley Posted May 24, 2012 Share Posted May 24, 2012 Because the element doesn't exist when the script executes, it won't create the event listener. You need a live listener: $('#pass-reminder').live('click', function() Quote Link to comment https://forums.phpfreaks.com/topic/263025-link-in-ajax-return/#findComment-1348185 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.