tags:

views:

31

answers:

2

This isn't working. I'm trying to replicate the animate to red and then remove effect as in the WordPress admin. The element gets removed, but it doesn't animate before that.

$('.delete-item').live('click', function(){
            $(this).parent().parent().animate({backgroundColor: '#ff0000'}, 'slow').empty().remove();
        });
A: 

Use the .animate() callback, like this:

$('.delete-item').live('click', function(){
  $(this).parent().parent().animate({backgroundColor: '#ff0000'}, 'slow', function() {
    $(this).empty().remove();
  });
});

The callback won't execute until the animation is complete, your current method queues the animation but only executes one frame of it before the element is removed from the DOM, this lets the entire animation execute then remove it.

Nick Craver
Thanks Nick. Now what happens is, there is a small waiting period before the element is remove, but he background color still doesn't change.
JorgeV44
@U22199 - I assumed you had the color plugin already for this, you'll also need to grab it from here to animate colors: http://plugins.jquery.com/project/color
Nick Craver
+1  A: 

As for as i know you can not animate the background color, you need the color plugin in order to do that.

Sarfraz
That was the problem. Thanks!!
JorgeV44
@U22199: You are welcome...
Sarfraz
@U22199: You should accept this answer if it was helpful!
Will Vousden