I have created a button and when the user clicks on it, the current class should be replaced with a new one and vice-versa. BUT addClass or removeClass, are both not showing any effect. I haven't seen any errors or warning msgs in console log.
JQuery code:
$('.vote_btn').click(function(){
$.ajax({
url:'/joseph/pages/votes.php',
type: 'post',
//dataType:'json',
data:{'comment_id':$(this).data('commentid')},
success: function(data){
if(data == 'up'){
$(this).removeClass('fa-thumbs-o-up').addClass('fa-thumbs-up');
} else if(data == 'reversed') {
$(this).removeClass('fa-thumbs-up').addClass('fa-thumbs-o-up');
} else {
alert(data);
}
}
});
});
HTML Code:
<span id="<?=$comment['id']?>" class="fa fa-thumbs-o-up vote_btn" data-commentid="<?=$comment['id']?>" data-postid="<?=$getpost['post_id']?>" data-who="<?=$comment['commenter_id']?>"></span>