views:

30

answers:

3

This is my code.

    v=dom.find("ul:first").outerHeight(); // the height of the first li element
            // instead of taking the height of the first li element, it should loop through all
            // li elements and set v to the element with the biggest height

The comment in the middle of the code pretty much explains everything. I need to loop through all li elements and take the biggest height, instead of taking the height of the first element.

+1  A: 

you can use the jquery .each() method to loop through each element, and the .height() method to determine the height of the element. to determine the greatest height, declare a variable, maxheight=0, and if the element height is greater than maxheight, set the maxheight to the element height.

var maxheight = 0;
$('ul').each(function(index) {
     if($(this).outerHeight() > maxheight) maxheight = $(this).outerHeight();
});
Orbit
+3  A: 
var v = 0;
// ...
dom.find('ul:first').children('li').each(function() {
    var height = $(this).outerHeight();
    v = height > v ? height : v;
});
jAndy
Thank you. It works great.
Peter
Nice answer , code is pretty clean with conditional operator
gov
A: 
var el, max = 0;
$("ul").each(function(){ 
  var height = $(this).outerHeight();
  if (height > max) {
    el  = this;
    max = height;
  }
});
galambalazs