Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery - Remove() after hide()

I have a div that I want to remove using remove(). I want to show an animation before/while removal of div. I have only been able to show the animation when hiding the div.

If i want to show the animation then do remove(). How is this done???

Code so far:

//Delete Button - delete from cart
$('.ui-icon-trash').live('click',function() {
    $(this).closest('li').hide("puff", {}, 1000)
});
like image 381
user342391 Avatar asked Jun 24 '10 20:06

user342391


People also ask

What is difference between remove and hide in jQuery?

hide() sets the matched elements' CSS display property to none . remove() removes the matched elements from the DOM completely. detach() is like remove() , but keeps the stored data and events associated with the matched elements.

What does hide () do in jQuery?

jQuery hide() Method The hide() method hides the selected elements. Tip: This is similar to the CSS property display:none. Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: To show hidden elements, look at the show() method.

How do I toggle show and hide in jQuery?

The toggle() method toggles between hide() and show() for the selected elements. This method checks the selected elements for visibility. show() is run if an element is hidden. hide() is run if an element is visible - This creates a toggle effect.


2 Answers

Do it in the callback function for .hide() (jQuery UI .hide() reference), like this:

$('.ui-icon-trash').on('click', function() {
  $(this).closest('li').hide("puff", {}, 1000, function() {
    $(this).remove();
  });
});

The function at the end runs as a callback, executing when the animation is done...so when you want :)

like image 93
Nick Craver Avatar answered Sep 28 '22 11:09

Nick Craver


You might check this also:

$(this).hide("puff").delay(10).queue(function(){$(this).remove();});
like image 41
Eray Avatar answered Sep 28 '22 13:09

Eray