Alex Rivera | Logout

selecting the true height of a DIV in jQuery

Asked 2010-10-08T11:46:06.590
9

I have a DIV defined with a fixed height:

.w {
  height: 100px;
  overflow: hidden;
}

if I put text in this it will hide everything that goes beyond the 100px. I have a button that shows all text, basically it does this:

$('.w').height('auto');

this will make all text visible, but I would like to animate this. And that won't work with height='auto', it has to have a specific height.

The question: how do I get the height the DIV should be to be able to show all text in it?

Edit
Report

1 Answer

15

try scrollHeight like this:

$('#ID_OF_DIV')[0].scrollHeight

Note [0], as it is property of DOM elements.

answered 2010-10-08T11:50:18.460

Your Answer