i am getting the expected result to json format. I want the icon to be changed when i click on id "#imp" with respect to the status field in db. The value in database are updating as i click but icon are not changed. I am getting problem when using if statement inside class to toggle between classes according to the status coming from json. I tried this code but it didn't worked for me. Any other good solution would be greatful for me. Thank you.
$("#imp").live('click',function(){
$this = $(this);
var ids = $(this).prev().prev().prev().prev().attr("class");
var impt = $(this).prev().attr("class");
var alllist = "";
$.ajax({
type: "POST",
url: "<?php echo base_url().'index.php/cms/mark_imp'; ?>",
dataType: "json",
data: {
'id' : ids,
'imp' : impt
},
beforeSend: function()
{
},
success: function(data)
{
var list_len = data.length;
for(var i=0;i<list_len;i++)
{
var imp_status = data[i].important;
alllist += '<li class="list-group-item"><span>' +
data[i].list + '</span><span class="pull-right"><span class="'+ data[i].id +'"></span>' +
'<i class="icon-pencil" style="color:#f8a326"></i> ' +
'<i class="icon-remove" style="color:#f34541;cursor:pointer" id="del_list" title="Delete"></i> ' +
'<span class="'+ data[i].important +'"></span><i class="" style="color:#00acec;cursor:pointer" title="Mark as important" id="imp"></i></span></li>';
if(imp_status === "0")
{
$this.addClass("icon-bookmark-empty");
}
if(imp_status === "1")
{
$this.addClass("icon-bookmark");
}
//here i want to add different class for different imp_status. Like given i want to add class icon-bookmark-empty when imp_status is 0 and when it is 1 i want to add icon-bookmark.
}
$("#inlist").html(alllist);
}
});
});