Ahmed Ahmed - 1 year ago 111
jQuery Question

Get div height in pixels although its height set to 100%

I wonder if there is any way to get div height in pixels, although its height set earlier to 100% height.

This is required as div content is dynamic so div height has different values based on content itself.

Div by default is hidden.

I need to get div height in pixels for later manipulation (smooth scrolling will be done for div)?

Is there any way to do this?

Answer Source

Since you tagged jQuery, use



For Plain Ol' Javascript, you can use element.clientHeight or element.offsetHeight, depending on which one suits your needs.

Since the div is hidden, you will have to .show() it before calling .height(), and you can hide it again straight away:

var $myEl  = $('#myElement').show();
var height = $myEl.height();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download