I believe I have a cleaner, better solution with a container:
<div id="menu_container"> <div id="menu"> <p>my content</p> </div> </div>
What I am doing is that I lock the maxHeight and minHeight of the container to the current div height. Then I change the contents of this div. And finally, I βlet goβ of the maximum and minimum height of the container to the current height of the inner div:
$("#menu_container").css("min-height", $("#menu").height()); $("#menu_container").css("max-height", $("#menu").height()); $("#menu").fadeOut(500, function() { //insert here the response from your ajax call var newHtml = serverResponse; $(this).html(newHtml).fadeIn(500, function() { $("#menu_container").animate({minHeight:($("#menu").height())},500); $("#menu_container").animate({maxHeight:($("#menu").height())},500); }); });
source share