I'd like the user to be able to remove an item from a list without having to reload the page, and am using jQuery/AJAX to do this. However, with my current code the divs are not being removed. I think I am traversing correctly, so not sure what the problem is.
See example here: http://jsfiddle.net/BbpWc/1/
HTML:
<img src="delete.png" onclick="delete_item(<? echo $row_item['id'] ?>);">
Javascript:
$(document).ready(function() {
delete_item=function(item_id){
var confirmation = confirm('Are you sure you want to remove this item?');
if (confirmation){
$.post(
"../../items.php?id="+item_id+"&i=delete"
)
$(this).parent('.item_container').remove();
}
else {
return false;
}
};
})
$().click()instead of inline-handlers. And you can store theIDin arel=""ordata-attribute.