How to get the DIV height in JavaScript
Use style.heigth
on the specific element.
document.getElementById("yourElementId").style.height;
Example:
<div id="myWarning" style="background: red; width: 60px; height: 60px;">Warning</div>
<script>
var elementHeight = document.getElementById("myWarning").style.height;
console.log(elementHeight);
</script>
Output (console): 60px
Optionally, you can also get rid of the “px” to get only the height number.
To do this, use the replace()
method.
Example:
<div id="myWarning" style="background: red; width: 60px; height: 60px;">Warning</div>
<script>
var elementHeight = document.getElementById("myWarning").style.height;
console.log(elementHeight.replace('px', ''));
</script>
Output (console): 60