Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting an element's inner height

Tags:

javascript

dom

How do you get an element's inner height, without padding and borders?

No jQuery, just pure JS, and a cross-browser solution (IE7 included)

enter image description here

like image 658
vsync Avatar asked Nov 17 '12 22:11

vsync


People also ask

How do you find the inner height of an element?

The innerHeight() method returns the inner height of the FIRST matched element. As the image below illustrates, this method includes padding, but not border and margin. Related methods: width() - Sets or returns the width of an element.

How do I get the height of an element in CSS?

HTML. outerHeight() It returns the current height of the element including the padding, border and margin optionally.

How do I increase my inner height?

To obtain the height of the window minus its horizontal scroll bar and any borders, use the root <html> element's clientHeight property instead. Both innerHeight and innerWidth are available on any window or any object that behaves like a window, such as a tab or frame.


1 Answers

var style = window.getComputedStyle(document.getElementById("Example"), null); style.getPropertyValue("height"); 

The above version will work in modern browsers. Please check currentStyle for IE browsers.

like image 147
Rajkamal Subramanian Avatar answered Sep 19 '22 20:09

Rajkamal Subramanian