1

I have at the moment in this JsFiddle code snippet 3 tables, the central table is named .sl_scrollingTable and the others .sl_NewFixedTable.

What I am trying to do is have each row have the same height on all three tables. It works for the first instance of .sl_NewFixedTable but not for the second. Not sure why, please help.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
mustafa
  • 303
  • 1
  • 4
  • 14

1 Answers1

0

You can use John Resig's Array.min and Array.max from his blog

I've updated your jsfiddle: http://jsfiddle.net/2uux2/1/

But, here's the code for anyone else to look at.

// document onload
Array.max = function( array ){
    return Math.max.apply( Math, array );
};
Array.min = function( array ){
    return Math.min.apply( Math, array );
};

var h= $('tr').map(function() {
        return $(this).height();
}).get();

var maxHeight = Array.max(h);
console.log('Max height: ' + maxHeight );

$('tr').css({height:maxHeight });
Joseph Yaduvanshi
  • 20,241
  • 5
  • 61
  • 69
  • Thank you so much for this. However im getting an error message in firebug "second argument to Function.prototype.apply must be an array return Math.max.apply( Math, array )" although it works great in js fiddle i cant seem to get it to work in the html im working on :( – mustafa Nov 23 '11 at 14:39
  • Ah, try `Array.max(h.get())` to get the array out of the jquery object. – Joseph Yaduvanshi Nov 23 '11 at 14:49
  • Thanks that seemed to work except it seems to be applying the max height to all rows instead of the max for each row, if that makes sense. Thank you so much for your help by the way – mustafa Nov 23 '11 at 14:54
  • Did you figure this out? You'd need an array of row heights for each table, then merge the arrays by index so that `a[0] = [ b[0], c[0], d[0] ]`. Then you'd loop through the rows and apply the css for the value at the index of the merged array (`a`). – Joseph Yaduvanshi Nov 28 '11 at 00:53
  • If got as far as writing this - $("table").each(function(index, element) { window["element"+index]=$('tr', this).map(function() { return $(this).height(); }).get(); this creates the arrays but i have no idea on how to check there indexes against eachother – mustafa Nov 28 '11 at 18:08