7

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?

MrSmith42
  • 9,961
  • 6
  • 38
  • 49
fabrik
  • 14,094
  • 8
  • 55
  • 71
  • 2
    see here: http://stackoverflow.com/questions/510761/jquery-delete-dom-element-after-fading-out – mamoo Nov 09 '10 at 13:16

3 Answers3

17

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."

lonesomeday
  • 233,373
  • 50
  • 316
  • 318
5

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.

RobertPitt
  • 56,863
  • 21
  • 114
  • 161
0

You need to queue the .remove()

_item.queue( function() { $(this).remove(); });
Simon
  • 4,395
  • 8
  • 33
  • 50