javascript - jQuery Set Height of Element to Highest in the group -


i'm trying work jquery find highest element first 3 elements within div set 3 same height check next 3 , set them.. etc.. if window width == x, if window width < x find highest 2 elements set them, next 2 next 2 etc.

this current code works elements, to go through elements in groups (2's , 3's) , set height group based on result , window size.

// find highest element , set elements height.     $(document).ready(function () {      // set options     var height = 0;     var element_search = "#cat_product_list #cat_list";     var element_set = "#cat_product_list  #cat_list";      // search through elements set , see highest.     $(element_search).each(function () {         if (height < $(this).height()) height = $(this).height();         //debug_(height,1);     });      // set height element(s if more one).     $(element_set).each(function () {         $(element_set).css("height", (height+40) + "px");     }); }); 

any appreciated :)

try setting of them max height:

$(document).ready(function() {   var maxheight = 0;   $("#cat_product_list #cat_list").each(function() {     if ($(this).outerheight() > maxheight) {       maxheight = $(this).outerheight();     }   }).height(maxheight); }); 

update 22/09/16: can achieve same thing without javascript, using css flexbox. setting container element have display: flex automatically set heights of elements same (following highest one).


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -