开发者

Getting total height of an element?

开发者 https://www.devze.com 2023-01-08 17:20 出处:网络
What\'s the right way to get the total height of a div element? I\'m trying this: element.outerHeight(true);

What's the right way to get the total height of a div element? I'm trying this:

element.outerHeight(true);

but when I take a screenshot of my page, and measure the height (in pixels) of the element, it seems to be a few pixels taller 开发者_开发知识库than what element.outerHeight() is reporting. Is there a different way? I'd like to include all padding/margin in my height.

Thanks


If you want to include the padding and border use outerHeight(false), if you want to include padding, border and margin use outerHeight(true) and if you want to include only the height of the element use height().


Use height() method instead:

 $('#element').height();


$(window).height();   // returns height of browser viewport
$(document).height(); // returns height of HTML document
0

精彩评论

暂无评论...
验证码 换一张
取 消