Ahmed Ahmed - 3 days ago 6
Javascript Question

How to “fadeOut” & “remove” in jQuery?

This is my code:

notification.hide().prependTo('body')
.fadeIn(500)
.delay(200)
setTimeout(function () {
jQuery('.notifications').fadeOut(700);
}, 5000);


what i need to remove the notification after appear in html but without lose fadeout effect, my code only hide the notification as display none and not remove it from html.

Answer

fadeOut has a callback as a second parameter, that gets called after the animation is done:

notification.hide().prependTo('body')
    .fadeIn(500)
    .delay(200)
    setTimeout(function () {
        jQuery('.notifications').fadeOut(700, function() {
            jQuery('.notifications').remove();
        });
    }, 5000);
Comments