Reputation: 11
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/
Upvotes: 0
Views: 367
Reputation: 41
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]")
Source: https://stackoverflow.com/a/25610045/969869
Upvotes: 0
Reputation: 21759
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.
Upvotes: 2