I need the full height of a div, I\'m currently using
document.getElementById(\'measureTool\').offsetHeight
offsetHeig
Vanilla JavaScript ECMAScript 5.1
height (including padding & border)var element = document.getElementById('myID'),
height = element.getBoundingClientRect().height,
style = window.getComputedStyle(element);
// height: element height + vertical padding & borders
// now we just need to add vertical margins
height = ["top", "bottom"]
.map(function(side) {
return parseInt(style['margin-' + side], 10)
})
.reduce(function(total, side) {
return total + side
}, height)
// result: compare with devtools computed measurements
document.querySelector('.result').innerText = 'Total height is: ' + height + 'px';
#myID {
padding: 10px 0 20px;
border-top: solid 2px red;
border-bottom: solid 3px pink;
margin: 5px 0 7px;
background-color: yellow;
}
.result {
margin-top: 50px;
}
element