Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery highlight effect before remove()

Consider the following snippet:

$('.remove_item').click(function(e) {
    var _item = $(this).closest('.cart_item');
    if(confirm('Biztosan törölhetem a terméket a kosárból?')) {
        _item.effect('highlight', {}, 100).stop().fadeOut('fast');
        _item.remove();
...

I'd like to highlight the actual row before trashing (.remove()) it. If i don't .remove() the item, highlight working.

How can i highlight first, then remove element?

like image 584
fabrik Avatar asked Nov 09 '10 13:11

fabrik


2 Answers

You can use the callback functionality of effect and fadeOut to do actions when the first action has finished:

_item.effect('highlight', {}, 100, function(){
    $(this).fadeOut('fast', function(){
        $(this).remove();
    });
});

This says "highlight _item. When this is finished, fade it out. When this is finished, remove it."

like image 68
lonesomeday Avatar answered Nov 09 '22 08:11

lonesomeday


Yo ushould be able to assign a callback on the fadeOut:

$('.remove_item').click(function(){
    if(confirm('Biztosan törölhetem a terméket a kosárból?'))
    {
         $(this).closest('.cart_item').fadeOut(500, function() { $(this).remove(); });
    }
});

hope this helps.

like image 5
RobertPitt Avatar answered Nov 09 '22 09:11

RobertPitt