JQuery how to get the height of each brother and sister?

I think this is a very simple question for those who are more experienced in jQuery.

for example, we have a simple html page with several divs, and 3 of them have the same css class 'sidebar'

Each of these “side” sections has different contents and different heights.

I need to compare this height divs and find the longest one.

I know how to implement a comparison, but I do not know how in jQuery I can take each of these divs

to store their value in a vairable or array.

+5
source share
3 answers
$.each($('.sidebar'), function() {
    var height = $(this).height();
});
+4
source

, , , jQuery.each(), each(), :

$('#elementID').siblings().each(function ()
{
    var height = $(this).height();
});

:

var heights = [];
$('#elementID').siblings().each(function ()
{
   heights.push($(this).height());
});

map():

var heights = $('#elementID').siblings().map(function ()
{
   return $(this).height();
}).get();
+13

When I had to do the same, this is the code I used:

    var tabPanels = $("...");
    var maxHeight = 0;

    $.each(tabPanels, function() {
        var height = $(this).height();
        maxHeight = (height > maxHeight) ? height: maxHeight;
    });

    $.each(tabPanels, function() {
        $(this).css("height", maxHeight + "px");
    });
0
source

All Articles