I have a couple of elements inside a preview <div>
. I need to add up their outerHeights
(NOT the total height of the preview <div>
). If height of elements reaches e.g. 300px, I need to trigger some action.
Firefox and Chrome are doing this well. IE Edge seems to add an additional line height per element. I figured out that this is because of <br />
tags at the end of each element. Seems they are handled as an additional line of text in Edge.
Comparing the boxes height in photoshop, I can see, that Firefox and Chrome are right. Edge counts much more height in total, than is visible.
I'm not able to manipulate the variable text inside my preview <div>
. Does anyone have an idea, how to fix it using jquery or javascript?
My html:
<div class="preview">
<span>Lorem ipsum, <br/></span>
<span><br/></span>
<span>Lorem ipsum doilor sit amet <br/></span>
</div>
<input type="text" id="t" value="0">
My jQuery:
var ct = 0;
$('.preview').children().each(function() {
ct = ct+$(this).outerHeight(true); // 'true' for including margins
});
$('#t').val(ct+"px - total height");
Please have a look on my fiddle in Chrome/firefox and compare to IE Edge
`. I still don't understand what is your end goal, counting heights of inline or inline-block elements is quite odd (well, unless your elements are defined as display block in CSS)... I really don't understand the purpose if your task. Given that, there might be other solutions - making this for now an *XY Question* – Roko C. Buljan Aug 14 '20 at 12:46