Get height of an element's content

user3186555

I have a div who's height is set to a pixel height with CSS. It's property overflow is set to hidden. It's contents are greater in size than the set height. How do I get the height of the div's content (all content in total; that is to say what would the height be if it was set to auto)? would var_representing_the_div.innerHeight work?

Here is an example of such div:

div{
  height:100px;
  overflow: hidden;
}
<div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean et neque eget mi aliquam malesuada. Vivamus purus augue, vulputate vel mi nec, tincidunt porta libero. Pellentesque scelerisque vulputate auctor. Integer nec tincidunt sapien. Pellentesque quis velit lorem. Fusce faucibus nec odio nec fringilla. Etiam mattis, massa nec eleifend faucibus, nunc mauris eleifend justo, auctor congue dolor sem eu turpis. Phasellus tincidunt urna cursus nibh commodo ultricies.
</p><p>
Curabitur ac tempor ex, quis tristique mauris. Morbi nisi est, vestibulum id viverra non, hendrerit et dolor. Vivamus nibh lorem, tempus at leo sit amet, bibendum elementum dui. Mauris viverra sollicitudin lacinia. Donec sed ante nulla. Quisque tincidunt tincidunt augue. Fusce ultricies, ante non mollis pretium, libero odio rutrum nisi, vitae iaculis quam ligula eu diam. Nullam non nulla dolor. Nulla blandit magna iaculis cursus accumsan. Curabitur ac nunc nec enim mattis molestie. Nam imperdiet quam id lorem gravida tristique. Phasellus est nibh, pulvinar ac ex sit amet, sollicitudin mattis sem. Praesent maximus sit amet augue sit amet sodales. Fusce placerat auctor odio, a vulputate tellus ultricies nec. Cras convallis eros ac ornare suscipit. Suspendisse gravida laoreet nisl, at tristique nibh cursus sit amet.
</p><p>
Suspendisse pellentesque quis massa et convallis. Proin laoreet bibendum nunc, ac fringilla dolor pretium eu. Maecenas nec diam mattis, rutrum magna sed, varius tellus. Pellentesque et sagittis risus, a laoreet neque. Phasellus sodales dapibus massa ac mattis. Phasellus sem eros, malesuada a accumsan sed, dapibus vel urna. Pellentesque eu purus odio. Mauris ligula lorem, tristique imperdiet porta vel, ultricies nec turpis. Sed cursus finibus tempor. Aenean elit velit, posuere id nibh sit amet, volutpat consequat arcu. Proin in eros ipsum. Aliquam at turpis non urna congue accumsan.
</p><p>
Vivamus tincidunt at ante eu imperdiet. Donec a dictum turpis, in pulvinar turpis. Proin et feugiat quam. Etiam sed dapibus elit, ut laoreet lorem. Duis mollis tortor at erat lacinia, id venenatis tortor eleifend. Pellentesque non eros sit amet lacus condimentum suscipit. Phasellus ornare eu elit in placerat. Nunc sed ultrices nunc. Nunc ut lacinia est. Pellentesque placerat porta mi, nec dapibus ante tempor a.
</p><p>
Donec at tortor vel eros lobortis feugiat. Fusce commodo sodales libero auctor volutpat. Phasellus imperdiet finibus erat, eget viverra libero viverra ut. Suspendisse non venenatis est, eget pretium urna. Integer convallis neque nec eros rutrum, id hendrerit ipsum pharetra. Etiam dictum elementum magna, elementum semper lectus fermentum et. Nam sagittis sagittis neque quis semper. Morbi hendrerit libero nec elementum elementum. Donec hendrerit tincidunt arcu, vel bibendum velit suscipit ac. Mauris dolor enim, semper eget libero eget, vulputate accumsan massa. Integer rhoncus egestas tellus et porta. Pellentesque fringilla ac risus nec lacinia. Morbi blandit orci tincidunt libero volutpat, at eleifend augue imperdiet. Nunc non blandit massa, et pharetra massa. Curabitur aliquet augue et elit placerat commodo sit amet id ante.
</p>
</div>

baao

You would use the scrollHeight property:

var el = document.getElementsByTagName('div')[0];
console.log(el.scrollHeight); // height with overflow

DEMO

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get the content of the bottom element of a flexbox to be 100% height its container

From Dev

Get height of page content

From Dev

Get ListView content height

From Dev

Get WebView's content height - Windows Phone 8.1

From Dev

How to get boostrap content to be enclosed in two column with the browser's height

From Java

ReactJS - Get Height of an element

From Dev

C# Render HTML to get element's height

From Dev

Match element's height

From Dev

jquery - animate height to the new content's height

From Dev

Setting viewpager height to content's height

From Dev

Onsen UI: Get content height

From Dev

get width height of iframe content

From Dev

get width height of iframe content

From Dev

Polymer customelements's content get inserted below the element?

From Dev

Curl - Php get element content that it's updated with ajax

From Dev

Polymer customelements's content get inserted below the element?

From Dev

Setting an element's height to the height available in the viewport?

From Dev

Setting an element's height to the height available in the viewport?

From Dev

Get unparsed element content

From Dev

Restrict element height to content, and maintain collapsed overflow

From Dev

DIV element not changing height with content in responsive theme

From Dev

JQuery animate element height after changing content

From Java

Get width/height of SVG element

From Dev

AngularJS - Cannot get height of an element

From Dev

Get height of element and use it in css

From Dev

AngularJS: How to get element height

From Dev

Get height of an element in Angular 2

From Dev

make element have the height of it's parent element

From Dev

javascript animate height while get new content

Related Related

HotTag

Archive