Any ideas on how to get a div\'s height without using jQuery?
I was searching Stack Overflow for this question and it seems like every answer is pointing to jQuery\'
try
myDiv.offsetHeight
console.log("Height:", myDiv.offsetHeight );
#myDiv { width: 100px; height: 666px; background: red}
<div id="myDiv"></div>
<div id="item">show taille height</div>
<script>
alert(document.getElementById('item').offsetHeight);
</script>
Jsfiddle
Here's one more alternative:
var classElements = document.getElementsByClassName("className");
function setClassHeight (classElements, desiredHeightValue)
{
var arrayElements = Object.entries(classElements);
for(var i = 0; i< arrayElements.length; i++) {
arrayElements[i][1].style.height = desiredHeightValue;
}
}
jsFiddle
var element = document.getElementById('element');
alert(element.offsetHeight);