natural .height() of an element with set height and overflow hidden
Trying to get the height of an element whose height is specified in the CSS.
So I am trying to animate the height of an item, where I have:
- <img id="myButton" src="myimage.jpg" />
- <div id="myDiv" style="height:50px;overflow:hidden">
- asdklf
- as;df
- asdf
- asdf
- asdf
- asdf
- asdf
- asdf
- </div>
Now I the height specified to start with so that I can toggle it with a button. However, I would like to animate this so that the height gets animated from "height:50px;" to "height:auto;"
Any ideas on how to do this?
I tried:
- var myHeight = $('#myDiv').height();
- $('#myButton').toggle(function(){
- $('#myDiv').animate({height: myHeight});
- $('#myDiv').css({'overflow' : 'visible'});
- },
- function(){
- $('#myDiv').animate({height: 50});
- $('#myDiv').css({'overflow' : 'hidden'});
- }
- })
However, it only registers as 50, even if the element is 500
any thoughts, let me know if I am not clear.