How to get a "car" height div

Therefore, when I set a fixed height in a div with jquery, for example $('div').height(200); , the value of $('div').height() always 200. Even if the content of this div exceeds this height (I use overflow:hidden ).

How can I get this true DIV height as if it were in "auto" mode?

+2
source share
2 answers

USING

 .scrollHeight() 

element.scrollHeight

with jquery try this

  $(selector)[0].scrollHeight 

DESCRIPTION

The scrollHeight element is a measurement of the height of the content of the element, including content that is invisible on the screen due to overflow.

Example

enter image description here

DEMO from Vega Answer

+6
source

Do you mean the hidden height of the content?

Vega - yes. The height of the contents of the div, including the part that hides when overflowing

Just set auto and get .height and return it to a fixed height.

 var $el = $('#test'); var tmp = $el.css('height'); var actualHeight = $el.css('height', 'auto').height(); $el.css('height', tmp); alert(actualHeight); 

DEMO: http://jsfiddle.net/sKZfF/

+3
source

Source: https://habr.com/ru/post/953101/


All Articles