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
jQuery delay() Method The delay() method sets a timer to delay the execution of the next item in the queue.
To delay a function call, use setTimeout() function. functionname − The function name for the function to be executed. milliseconds − The number of milliseconds. arg1, arg2, arg3 − These are the arguments passed to the function.
setTimeout() The setTimeout() function is used when you wish to run your JavaScript function after a specified number of milliseconds from when the setTimeout() method was called. where expression is the JavaScript code to run after the timeout milliseconds have elapsed.
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();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With