My solution is similar to inorganik in that it works for any number of elements with a given class, except that I save auto-heights in the height attribute for each element instead of an array. This makes the automatic height of any element easily accessible as $ (this) .attr ('height').
Load the page, save the auto heights, and then set the elements to the desired height:
$(function() { $('.element').each(function() { $(this).attr('height', $(this).height() + ''); }) $('.element').css('height', '20px'); });
Then instead of $ ('. Element'). animate ({height: 'auto'}), you can say the following:
$('.element').animate({height : $(this).attr('height')})
mgrahamjo
source share