I have an ajax image uploader that I am currently trying to do a delete link for, I have the delete script working, but on success I want it to also remove the div
and replace with "Image Deleted" text, but I am a little confused on how to remove a div
where the id
will always be different (set from a var).
$(function(){
$(document).on('click','.trash',function(){
var image_id= $(this).attr('id');
$.ajax({
type:'POST',
url:'/includes/delete_image.php',
data:{'image_id':image_id},
success: function(data){
if(data=="YES"){
$('#image_id').remove()
}else{
alert("can't delete the row")
}
}
});
});
});
That's the code, so on data=="YES"
I want this:
<div id="image_id">
<img src=\"/uploads/articles/article_images/image_name" class='imgList'><br />
BBCode: <input type="text" class="form-control" value="[img]http://www.prxa.info/uploads/articles/article_images/{$image_name}[/img]\" /><br />";
<a href="#" id="image_id" class="trash">Delete Image</a>
</div>
To be deleted, where "image_id"
will be a number set as "image_id"
in the ajax code, any pointers? I am doing it horribly wrong right now heh.
"image_id" is different everytime of course.