CsharpBeginner CsharpBeginner - 1 month ago 17
jQuery Question

Getting biggest height of group of divs

I need to find the height of the biggest div in a group of divs with the class name termPanel.
How do I access each 'termPanel' div in the terms array?

function resizePanelsToBiggest(){

var maxheight = 0;

var terms = $('.termPanel');

for(var i = 0;i<terms.length;++i){

if(maxheight < terms[i].height){
maxheight = terms[i].height;
}


}

}

Answer

Check this demo:

 resizePanelsToBiggest();
 
 function resizePanelsToBiggest() {
     var maxheight = 0;
     var terms = $('.termPanel');
     terms.each(function(ndx){
     	if ($(this).height() > maxheight) {
        	maxheight = $(this).height();
        }
     });
     console.log(maxheight);
 }
.termPanel {
    width: 90px;
    display: inline-block;
    vertical-align: top;
    color: white;
}

.termPanel:nth-of-type(even) {
    background: black;
}

.termPanel:nth-of-type(odd) {
    background: red;
}

.termPanel:nth-of-type(1) {
    height: 100px;
}

.termPanel:nth-of-type(2) {
    height: 250px;
}


.termPanel:nth-of-type(4) {
    height: 400px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="termPanel"></div>
<div class="termPanel"></div>
<div class="termPanel">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut temporibus reiciendis officia veniam quos id velit quibusdam, asperiores ipsum. Obcaecati illum, hic facere repellat dolor modi commodi eum tenetur voluptas veritatis expedita consequuntur repellendus provident error, nisi quos! Aliquid error consectetur voluptates ea dicta, vero, dolores numquam, rerum quasi molestias nemo. Explicabo tenetur, omnis quos unde iusto, necessitatibus consectetur, dolorem deleniti atque doloremque repellendus earum quae sit sint, inventore nesciunt sapiente perspiciatis voluptatum corporis soluta at fugiat. Delectus excepturi unde eos deleniti soluta natus commodi ipsum sit et veniam! Eius aut, ut, ad commodi at esse facere asperiores repellat labore alias nostrum, consequatur tempora illo quasi. Nulla deleniti, mollitia soluta, repellat fugiat officiis voluptatibus odio distinctio libero, illo delectus obcaecati!</div>
<div class="termPanel"></div>