I have a link that posts to a url (ajax). Then I want to hide the entire li.
HTML
<li>Product Name <a href="/delete/item_id" class="del">Delete</a></li>
JQUERY
$(function(){
$(".del").click(function () {
var link = $(this).attr('href');
$.post(link, function() {
$(this).parent().slideUp();
return false;
});
event.preventDefault();
});
});
The
this-keyword in the success-handler passed to $.post does not refer to the anchor element, so your code won’t work. You can easily fix this by saving a reference to theli-element outside the success-handler: