0

This is my previous code. It only hides the parent targeted container:

$(".black-icon").click(function() {
  var taskid = $(this).parent().attr('id');
  $("#" + taskid).parentsUntil(".container").hide("slide", {
    direction: "right"
  }, 500);
});    

Here is the setTimeout that I added so that it gets removed and not only hidden:

$(".black-icon").click(function() {
  var taskid = $(this).parent().attr('id');
  $("#" + taskid).parentsUntil(".container").hide("slide", {
    direction: "right"
  }, 500);
  setTimeout(() => {
    $("#" + taskid).parentsUntil(".container").remove();
  }, 1000);
});  

Update: Is there a way I could use the same slide function (jQuery UI) with remove?

void
  • 36,090
  • 8
  • 62
  • 107
Parth Agarwal
  • 137
  • 1
  • 1
  • 11

1 Answers1

0

.hide has a callback which executes when the animation is finished. You can use that.

$("#" + taskid).parentsUntil(".container").hide("slide", {
    direction: "right"
  }, 
  500, 
  function(){
     $(this).remove();
  }
);
void
  • 36,090
  • 8
  • 62
  • 107