Когда вы используете .click()
, это событие привязки к целевому селектору, но после щелчка его класс меняется на другой.Для этого следует использовать делегирование события .
$(document).on('click', '.save-post', function(){
$(this).text('Unsave Post');
$(this).removeClass('save-post');
$(this).addClass('unsave-post');
});
$(document).on('click', '.unsave-post', function(){
$(this).text('Save Post');
$(this).removeClass('unsave-post');
$(this).addClass('save-post');
});
$(document).on('click', '.save-post', function(){
$(this).text('Unsave Post');
$(this).removeClass('save-post');
$(this).addClass('unsave-post');
});
$(document).on('click', '.unsave-post', function(){
$(this).text('Save Post');
$(this).removeClass('unsave-post');
$(this).addClass('save-post');
});
.save-post {color: red}
.unsave-post {color: blue}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-2 col-sm-2 col-md-2 drop">
<a href=""><i class="fa fa-ellipsis-v post-drop"></i></a>
<div class="drop-content">
<ul>
<li class="save-post">Save post</li>
<li>Report post</li>
<li>Hide post</li>
<li>Unfollow User</li>
</ul>
</div>
</div>