$('#followUser').click(function () { var userId = $(this).attr('data-userId'), action = $(this).attr('data-action'), currentUser = $(this).attr('data-currentUserId'), elem = $(this); $.ajax({ method: 'POST', url: "/sci-profile/profile/follow", data: { userId: currentUser, profileUserId: userId, action: action }, success: function(response) { elem.parent().load(window.location.href + ' #unFollowUser'); } }); });
After clicking the button, JS loads the new div with all the contents, which is good, but the problem starts from the moment the new div is loaded.
JS does not recognize the new ID . And when I press the new button, nothing happens because the JS function is loaded when the new element does not exist.
Is there a way to make some kind of listener to check the loads of the new DIV , and then load also the JS function corresponding to this ID element?
source share