Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
91
rated 0 times [  92] [ 1]  / answers: 1 / hits: 25351  / 14 Years ago, wed, june 23, 2010, 12:00:00

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.



[Edit]
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?


More From » jquery

 Answers
37

Since you tagged jQuery, use



$(#myElement).height();


http://api.jquery.com/height/



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();
$myEl.hide();

[#96424] Saturday, June 19, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
carolinabritneyp

Total Points: 75
Total Questions: 102
Total Answers: 105

Location: Armenia
Member since Fri, Apr 16, 2021
3 Years ago
;