Giberno Giberno - 7 months ago 6
Javascript Question

How to get div height after the action slider down or slider up?

Code in here: jsfiddle Demo

I wanna to get the

div#content
height when it finish the action of
slider down/up
.

For example, in demo, I type some words, they make the div height is
36px
, so if I click
slider down
, I need get the value
36
, and if I click
slider up
, I need return the value
0
. Thanks.

Answer

Then, but it in the callback function of the slideDown or slideUp, for example like:

 $('#content').slideDown('slow', function(){
        var height = $(this).height();
  }); 

Demo

Notice that it will give you the same height 38 in the two cases the slideDown and the slideUp, becouse the two functions don't change the height property of the div, but only the display proprty from none to block, so the div #content's height property is the same after slideing down as it's height before.

Comments