I have one div and more than one data es into this div by jstl tag. I want to find max content div height. I have seen one link but it is show in alert every time 20. element with the max height from a set of elements
JSP
<div id="div-height" class='cat-product-name'>${i.name} </div>
JAVA SCRIPT
$(window).load(function () {
var maxHeight = Math.max.apply(null, $("#div-height").map(function ()
{
return $(this).height();
}).get());
alert(maxHeight);
});
I want to find max height of div and set this height of every div.
I have one div and more than one data es into this div by jstl tag. I want to find max content div height. I have seen one link but it is show in alert every time 20. element with the max height from a set of elements
JSP
<div id="div-height" class='cat-product-name'>${i.name} </div>
JAVA SCRIPT
$(window).load(function () {
var maxHeight = Math.max.apply(null, $("#div-height").map(function ()
{
return $(this).height();
}).get());
alert(maxHeight);
});
I want to find max height of div and set this height of every div.
Share Improve this question edited May 23, 2017 at 12:07 CommunityBot 11 silver badge asked Feb 20, 2016 at 9:25 Varun SharmaVarun Sharma 4,84213 gold badges55 silver badges105 bronze badges3 Answers
Reset to default 6You can try this:-
$(document).ready(function() {
var maxHeight = -1;
$('.cat-product-name').each(function() {
maxHeight = maxHeight > $(this).height() ? maxHeight : $(this).height();
});
$('.cat-product-name').each(function() {
$(this).height(maxHeight);
});
});
Reference - Use jQuery/CSS to find the tallest of all elements
Each element id on the page must be unique, i.e. you can't have multiple elements with
id="div-height"
Try using class instead (class="div-height"
). Note you'll have to adjust your jQuery selector as well to
$(".div-height")
A modern take to this problem is the usage of css flex-box with align-items: stretch;
:
.container {
display: flex;
flex-wrap: wrap;
align-items: stretch;
width: 250px;
}
.container>div {
flex: 0 0 100px;
outline: 5px solid #888;
padding: 10px;
}
<div class="container">
<div>Small content</div>
<div>This divs content needs more height than their siblings!</div>
<div>Some more text</div>
<div>Other text</div>
</div>