Follow unfollow

Follow unfollow

 

<div class="btn-01765" id="followbtn"><p><a data-do='follow' data-user-id='{{ $user->id }}'><i
class="fa fa-heart-o"></i> Follow</a></p></div>
<!--new-left-end-->

<script>

$(document).ready(function(){

$('.btn-01765').click(function(){

let checkLoginOrNot = '<?php echo Session::get('user_name'); ?>';

if(!checkLoginOrNot){
window.location.href = "/login";
die();
}

let followersNo = $('#noOfFollowers').text();
followersNo = Number(followersNo);
let attrValue = $('.btn-01765 > p > a').attr('data-do');

if(attrValue == 'follow'){
followersNo = followersNo + 1;
$('#noOfFollowers').text(followersNo);
}

if(attrValue == 'unfollow'){
followersNo = followersNo - 1;
if(followersNo < 0){
followersNo = 0;
}
$('#noOfFollowers').text(followersNo);
}
});

});


</script>

Leave a Reply