以下はcssとjqueryのコードスニペットです
.star {
background-color: transparent;
background-image: url('http://localhost/technicalkeeda/images/star-off.png');
background-repeat:no-repeat;
display: block;
height:16px;
width:16px;
float:left;
}
.favorited {
text-indent: -5000px;
background-color: transparent;
background-image: url('http://localhost/technicalkeeda/images/star-on.png');
background-repeat:no-repeat;
height:16px;
width:16px;
float:left;
}
$(document).ready(function(){
$('.star,.favorited').click(function() {
var id = $(this).parents('div').attr('id');
var className = $(this).attr('class');
var flag = (className=='star') ? 'Y':'N';
var $this = $(this);
$.ajax({
type: "post",
url: "yoururl",
cache: false,
data:{'bookmarkId': id,'flag':flag},
success: function(response){
if(response=='true'){
$this.toggleClass("favorited");
}
},
error: function(){
alert('Error while request..');
}
});
});
});