Simple one line of html:
<div onclick="alert(this.style.height)">sometext</div>
and alert gives:
but it should be like 10px
or sth like that.
height() It returns the current height of the element. It does not include the padding, border or margin. It always returns a unit-less pixel value. Note: The height() will always return the content height, regardless of the value of CSS box-sizing property.
In JavaScript, you can use the clientHeight property, which returns an element's height, including its vertical padding. Basically, it returns the actual space used by the displayed content. For example, the following code returns 120, which is equal to the original height plus the vertical padding.
var height = document. getElementById('content'). clientHeight; That will not include any borders or scrollbars in the element, just padding.
Use offsetWidth & offsetHeight properties of the DOM element to get its the width and height.
When you use this.style.height, the height must have been specified on the element first, like this:
<div style="height: 15px;" onclick="alert(this.style.height)">sometext</div>
Otherwise, you should probably use offsetHeight or clientHeight:
<div onclick="alert(this.offsetHeight)">sometext</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With