I have a menu in which every item has a content updated via ajax (putted in the "content" div).
<ul id="menu">
<li class="gr" on><a href="#">Home</a></li>
<li class="yel"><a href="#">Products</a></li>
<li class="bl"><a href="#">Contact</a></li>
</ul>
<div class="container">
<div id="content">
</div>
</div>
In the $.ajax
success()
function, where I put the ajax received data in "content" div, I want to resize div height with animate(). here the steps:
- get the old "content" height
- update the "content" div with the ajax received data
- take the new height
- animate using the height difference.
So I wrote:
success : function (data) {
var contHeight = $("#content").height(); //older "content" height
$('#content').html(data); //update "content"
var diffHeight = $("#content").height() - contHeight; //difference from new and old height
$('#content').animate({height: '+=' + diffHeight + 'px'},500);
}
I tried my code (using some alert()
functions for debugging) and I noticed that: if I use animate()
, contHeight
it's equal to the "content" height after the data update(so old height is equal to the new one) and there is no animation. On the other hand, if I remove animate()
old and new heights are different. Seems that animate()
doesn't permit the update of the "content" height.