views:

275

answers:

3

Hello, why is the height value of the test div the same before and after the hide animation?

$(document).ready(function() {        
    $("#test").hide("slow", function() {  
       alert($("#test").height());  
   });
});

<div id="test">
    test
    <br />
    test
    <br />
    test
</div>
+2  A: 

Hide() function only hides the div, it doesn't modify the height. Only adds a style="display: none;" to the element.

Elzo Valugi
I see thanks a lot.
Pickels
+1  A: 

I'm not completely sure on how the hide() animation works exactly, but if it does change the stlye-size of the element to achieve the shrinking effect, it probably reverts that to the original size after the animation is done.

The way jQuery really hides things is by setting one of the css styles which hides an element (I think it just sets display: none;). The animation is just some fancy effects that don't really permanently change the element.

Sean Nyman
the animation is provided by a callback calling the effect library prior to hide()
Elzo Valugi
Thanks for the anwser i guess i'll manually set the height to 0 after the animation is done.
Pickels
you can do $("#test").hide("slow", function() { alert($("#test").height()); }).height(0);
Elzo Valugi
A: 

you can wirte in the callback style.height=' ';

adardesign