In my current project, I am implementing follow and unfollow buttons. The follow functionality is working smoothly, but I'm facing an issue with the unfollow button. When I click on it, it doesn't switch back to follow. You can find the complete code snippet on JsFiddle.
$(".follow").live('click', function(e){
e.preventDefault();
$button = $(this);
if($button.hasClass('unfollow')){
//$.ajax(); Perform Unfollow
$button.removeClass('follow');
$button.removeClass('unfollow');
$button.text('Follow');
}
else {
// $.ajax(); Perform Follow
$button.addClass('follow');
$button.text('Unfollow');
} });