Search code examples
jqueryjquery-uidelay

Why can't I delay a remove call with jQuery


I would like for a div to fadeOut and then be removed:

 $('#div').delay(1000).fadeOut(300);
 $('#div').delay(1300).remove();

Unfortunately, this just directly removes the div, with no delays. Why is it that I can't get the remove action to be delayed? What solutions are there?

Thanks


Solution

  • If you want the element to be removed after it's done being faded out, you can fadeOut's callback parameter.

    $('#div').delay(1000).fadeOut(300, function(){
       $(this).remove();
    });