I have a div id'ed #scenario which has a number of <p> elements as children. I want to have a function that fades them out one by one in reverse order and then removes them from the DOM. I'm using jQuery.
My code:
function fadeAndDelete() {
var elements = $("#scenario").children().get().reverse();
$.each(
elements, function(index, element) {
element.animate(
{'color': 'rgba(0, 0, 0, 0)'}, 1000, function() {
$(this).remove();
}
);
}
)
};
I also tried to use element.remove() and $(element).remove(), and none of them worked.
Bonus points: in an ideal world, there would be a time-gap between the removals of the element (as if using a sleep() function inbetween the each() cycles).