Reputation: 1779
good Day
I want to calculate the outerheight of 3 elements and return the biggest one, since their sizes can vary at any given time...
Here is what I have:
var a = $('#latestInner').outerHeight();
var b = $('#make').outerHeight();
var c = $('#models').outerHeight();
if (a > b, c) {
a = x;
}
else if (b > a, c) {
b = x;
}
else if (c > a, b) {
c = x;
}
How would I proceed? I know I can probably use an array but not sure how to..
Upvotes: 0
Views: 134
Reputation: 74096
Use Math.max
:
Returns the largest of zero or more numbers.
Math.max([value1[,value2[, ...]]])
Using jquery you can do:
var max = Math.max.apply(null, $.map($('#latestInner, #make, #models'), function(n){
return $(n).outerHeight();
}));
Upvotes: 5
Reputation: 193261
You can calculate max using each method:
var max = 0;
$('#latestInner, #make, #models').each(function() {
max = Math.max(max, $(this).outerHeight());
});
If you need to update the height of the divs to be the same you can set it right away:
var max = 0;
$('#latestInner, #make, #models').each(function() {
max = Math.max(max, $(this).outerHeight());
})
.height(max);
Upvotes: 2