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
  • 17,123
  • 23
  • 80
  • 128

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
  • 103,943
  • 14
  • 161
  • 157
0

Try

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

$t.remove();

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

});

Neeraj Dubey
  • 4,401
  • 8
  • 30
  • 49