I just want to show "Delete" link if I have more than one image in my images list
Im deleting banner images using jQuery and Ajax,but when I have just one image in my list I dont want to delete it.
I have a list of images, and for each image I have a "Delete" link:
-
echo '<a class="delete j_bannerdelete" id="'.$rslt_banner['id'].'" href="#">Delete</a> ';
But its not working correctly. When I have two images and I click to delete one, I delete it, but my last image stays with delete link. And only if I refresh the page my delete link stays hidden. But I want to hide my link in the moment that I delete my penultimate image.
Anyone can help me in this issue please?
-
$(function(){
//I cal my function to hide my "Delete" link if I have only one image in my bannerli list
disableDeleteIfOnlyOneItem(1);
- $(function(){
var banid = null;
$("a#no").click(function(event){
event.preventDefault();
$('.confirm').fadeOut("slow",function(){
$('.delete_dialog').fadeOut("slow");
});
$('.bannerli li[id="'+ banid +'"]').css('background','#f5f5f5');
banid = null;
});
$("a#delete").click(function(event){
event.preventDefault();
if (!banid) return;
$.post(url,{action:'img_delete',id: banid},function(){
window.setTimeout(function(){
$('.bannerli li[id="'+ banid +'"]').fadeOut("slow");
},500);
$('.confirm').fadeOut("fast",function(){
$('.delete_dialog').fadeOut("fast");
});
disableDeleteIfOnlyOneItem(2); //call function to hide "Delete" link if there is just 1 image
});
});
$('.bannerli').on('click','.j_bannerdelete',function(){
banid = $(this).attr('id');
$('.bannerli li[id="'+ banid +'"]').css('background','red');
$('.delete_dialog p').text('Are you sure you want to remove this image?');
$('.delete_dialog').fadeIn("slow",function(){
$('.confirm').fadeIn("slow");
});
return false;
})
});
- });
My functin to hide my "Delete" link if I have only one image:
- function disableDeleteIfOnlyOneItem($value) {
if($('.bannerli li').length <= $value) {
$('.j_bannerdelete').hide();
}
}