theHaggis theHaggis - 4 months ago 10
Javascript Question

How to change background color to a <DIV /> then fade out, then finally remove from the DOM?

Hi I want to first change the background color of a

<div>
to red then fade out that
<div>
. Once the fade out is completed remove it from the DOM.

The following code does fade out the
<div>
and remove it from the DOM but it doesn't change the
background-color
to red.

$(this).find("div#" + id)
.css("background-color", "#ff0000")
.fadeOut("slow", function () {
$(this).remove()
});

Answer

See the working solution here:

<div id="div1">
    test<br>
        test<br>
        test<br>

        test<br>
</div>