I was trying to get the height of an element with jQuery but it was returning undefined
Code:
alert($('.forIndex').scrollHeight())
Please any help will be greatly appreciated at: http://www.tulzmasterz.com/tutorials/
I was trying to get the height of an element with jQuery but it was returning undefined
Code:
alert($('.forIndex').scrollHeight())
Please any help will be greatly appreciated at: http://www.tulzmasterz.com/tutorials/
If you wan't to get the height as you stated in your question, use height
:
alert($('.forIndex').height())
In order to use scrollHeight
, the element should have indeed a scroll, by setting it's css attribute overflow
to scroll
, or auto
(and the height of the element should be shorter than the content inside, so that the content generates a scroll.
To get the scrollHeight of a jQuery element you will need to select the first element from the query.
Example:
alert($('.forIndex')[0].scrollHeight())
(notice the "[0]")