I've got this code in twig
{% if followsId == null %}
<div id="followUser" class="follow" data-userId="{{ profileUserData.id }}" data-currentUserId="{{ loggedUserData.id }}" data-action="follow">
Follow
</div>
{% else %}
<div id="unFollowUser" class="follow" data-followsId="{{ followsId }}">
Unfollow
</div>
{% endif %}
I just wanted to change content and functionality to button on click and tried this code with jQuery
$('#followUser').click(function () {
var userId = $(this).attr('data-userId'),
action = $(this).attr('data-action'),
currentUser = $(this).attr('data-currentUserId');
$.ajax({
method: 'POST',
url: "/sci-profile/profile/follow",
data: {
userId: currentUser,
profileUserId: userId,
action: action
},
success: function(response)
{
$('#followUser').attr('id', 'unFollowUser')
.text('Unfollow')
.fadeOut(50)
.delay(50)
.fadeIn(50);
}
});
});
With this code on page source I see different ID and different text on button but when click second time I call first button like it had never changed. Is there some way to refresh memory for that element or I do wrong thing from start?