Refresh jquery.masonry when deleting an item

Freeman picture Freeman · Mar 5, 2011 · Viewed 12.6k times · Source

How do I refresh Masonry when an item is deleted via Ajax? This is the code I'm using to delete the item:

if($deletes = $('a[rel=delete]')) {
    $deletes.click(function() {
        if(!window.confirm('Are you sure you wish to delete this picture?'))
            return false;
        $t = $(this);
        $.post(
            $t.attr('href'),
            {},
            function(data) {
                if(data == "success")
                    $t.parents('.deleteable:first').fadeOut();
            }
        );
        return false;           
    });
}

The reason I want a refresh is to eliminate the resulting spaces after items are deleted.

Answer

John Flatness picture John Flatness · Mar 6, 2011

Add a callback to your fadeOut() to actually call .remove() your deleted element once it's faded out, then just call .masonry() on the container again.