views:

486

answers:

5

$target.remove() can remove the element,but now I want the process to be down with some feel animation,how to do it?

+3  A: 
target.fadeOut(300, function(){ $(this).remove();});

or

$('#target_id').fadeOut(300, function(){ $(this).remove();});

Duplicate: http://stackoverflow.com/questions/553402/jquery-fadeout-remove

micahwittman
+4  A: 
$target.hide('slow');

or

$target.hide('slow', function(){ $target.remove(); });

to run the animation, then remove it from DOM

edit: not sure why I'm getting voted down for this...

Greg
This won't remove the element from the DOM. It only hides the element.
rahul
I need it to be exactly removed.I tried $target.hide('slow').remove() but not working。
Mask
In that case: $target.hide('slow', function(){ $target.remove(); });
Greg
@Mask -- you need to chain that. It removes it as soon as it starts the animation, so you have to put the remove in the callback
Greg
Yup,works now,ty!
Mask
The .remove() method very specifically removes the node from the DOM. The .hide() method only changes the display attribute to make is not visible, but still in existence.
micahwittman
@Greg,+1 for it works:)
Mask
A: 

You mean like

$target.hide('slow')

?

Jeremy Morgan
Yes,but I also need to delete it after animation.
Mask
A: 

If you need to hide and then remove the element use the remove method inside the callback function of hide method.

This should work

$target.hide("slow", function(){ $(this).remove(); })
rahul
A: 

You need to use an animation before calling the remove method.

See: http://stackoverflow.com/questions/308019/jquery-slideup-remove-doesnt-seem-to-show-the-slideup-animation-before-remov

Jonathan