0

I basically have a button to delete something and the code is:

$(document).on('click','.btn',function(){
    //code here
    //$t is the item to delete
    $t.remove();
});

now I would like to execute the following code after the remove or on has finished:

if($('#bookmarks').is(':empty')){
    $('#bookmarks').css('visibility','hidden');
}

I tried adding this into the .on:

$t.on("remove", function () {
    if($('#bookmarks').is(':empty')){
        $('#bookmarks').css('visibility','hidden');
    }   
});

but that didn't work. So how can I execute that function after the item has fully been deleted?

Ryan Saxe
  • 16,019
  • 22
  • 75
  • 123

2 Answers2

5

Simple, just execute it after you call remove()

$(document).on('click','.btn',function(){
    //code here
    //$t is the item to delete
    $t.remove();

    //remove done, next
    if($('#bookmarks').is(':empty')){
        $('#bookmarks').css('visibility','hidden');
    }
});
tymeJV
  • 102,126
  • 13
  • 159
  • 155
0

Try

$(document).on('click','.btn',function(){

$t.remove();

//remove done
if($('#bookmarks').is(':empty')){
    $('#bookmarks').hide();
}

});

Neeraj Dubey
  • 4,333
  • 8
  • 27
  • 47