$('#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 on button, JS load new div with all its content, which is good, but problem starts at the moment when new div is loaded.
JS don't recognize new ID
. And when I click on new button nothing happens because JS function has loaded when new element doesn't existed.
Is there a way to make some listener to check loads of new DIV
and then load also JS function corresponding to that element ID
?