tags:

views:

27

answers:

2

I am using jQuery 1.4.1 .

a = $('#hello')
          .animate({height: '100px'});
a.hide();

Above code does not hide the element. I know the solution. The solution is

 a.animate({height: 'hide'});

However I am interested in finding out what does animate do to the elements which makes them not respond to hide. I looked into the source code but could not find an answer.

Does anyone know?

+3  A: 
a = $('#hello')
          .animate({height: '100px'});
a.hide();

the problem i see is, after you call animate function it moves on to hide immediately. so it starts animating then hide() hides it and it continues animatning which would show it again. you want something like

$('#hello').animate({height: '100px'},2000,function(){$(this).hide()});
Funky Dude
I may be silly, but http://docs.jquery.com/Effects/animate shows that the 3rd argument for animate is 'easing'. Shouldn't you be using the 4th? (callback)
Daniel
I don't follow you. What you are suggesting is 1)animate 2)hide 3)animate again. Where is the instruction to animate again?
Nadal
@Daniel notice the [] around the parameter which make the paremeter optional ..
Gaby
@dorelal animate is slow. by the time you call hide, animate is still working.
Funky Dude
A: 

Problem is that animation take some time to complete ..

While it is in progress the selected element will remain visible..

Funky Dude has provided the correct alternative ..

Gaby
I am not looking for alternative as I mentioned in the question. I want to know what does animate do to the elements which makes them not respond to hide.
Nadal
@dorelal: the element actually -does- hide, animate() however continues animating towards a height of 100px over a specific time duration, which makes it visible again.
Daniel