javascript - how to find real DIV height? -
i have following html structure:
<div id="container"> <h1>this h1 element</h1> </div> when try find height of container in firefox or chrome div using javascript:
var container = document.getelementbyid("container"); var offsetheight = container.offsetheight; i wrong offsetheight (also if used clientheight). height of h1 , not margin-before/margin-after surround element.
is there way real height?
here's function think you:
function outerheight(elem){ var curstyle = elem.currentstyle || window.getcomputedstyle(elem); outerheight = elem.offsetheight; outerheight += parseint(curstyle.margintop); outerheight += parseint(curstyle.marginbottom); console.log(outerheight); //return outerheight //if you'd return outerheight } just call this:
<div onclick="outerheight(this)" id="container"> <h1>this h1 element</h1> </div> the outer height printed in console, can return if need be.
here's demo
Comments
Post a Comment