views:

34

answers:

2

Hi

I wanted to get <textarea> scrollHeight on body load using jquery. It's always getting zero. I want actual height of textarea on body load.

If it's not possible to get scrollheight on body load, is ther any way to get actual height rather than height().

Please suggest if you have any reference.

Thanks

-Pravin

+2  A: 

You just want the height? On load, it shouldn't be scrolled at all...

$('textarea').height();

Though textarea should be replaced by the #id selector.

Scrollheight:

var myTA = $('#myTextArea');
alert(myTA[0].scrollHeight);

You can test this here: http://jsfiddle.net/Lg5Ne/

Fosco
hey thanx Fosco...bt how do i get scrollheight instead of height()? that's right it shouldnt scrolled but still, is ther any way to get actual height rather than height().
pravin
It doesn't have a scrollheight until it has a scrollbar. That depends on the content of the textarea.
Diodeus
@Diodeus: thanx for reply, the content present in textarea has huge data, until and unless user click on textarea i m not getting scrollheight.
pravin
@Diodeus I added an answer for that with a link to see it working.
Fosco
Fosco's example seems to work fine. What does it do you pravin?
Diodeus
Yes, this is good code, worked correctly for me too...thanks folks.
pravin
A: 

if you want the scroll height of the textarea do something like

$('textarea#text').get(0).scrollHeight

or

just the height of textarea

 $('textarea#text').css('height') // in px
Ninja Dude