I want to animate a change in height (when I hide / show a div) using jQuery. I found some examples on SO, but I can't get them to work.
Let's say I have a container with some divs in it.
HTML:
<div class="container">
<div class="first">Show first div</div>
<div class="second">Show second div</div>
<div class="item1">
Some text
</div>
<div class="item2">
Some multiline<br />text
</div>
</div>
JQuery
$('.first').on('click',function(){
$('.item2').hide();
$('.item1').show();
});
$('.second').on('click',function(){
$('.item1').hide();
$('.item2').show();
});
http://jsfiddle.net/ytW69/2/
When I press div.first, I want to show div.item1, when I press div.second, I want to show div.item2. The height of these divs is different, which means that the size of the container changes when I hide / show divs.
How can I change this height change without knowing the size of any div?
ps. if there is a CSS solution, it will be even better. I don't think this is only possible with CSS tho.
source
share