tags:

views:

279

answers:

1

How can i add the total width off all submenu li's to the submenu ul?

width() method of jQuery?

<ul>
 <li>level 1</li>
 <li>
  <ul style="widht:150px;"> //total width children li / add width li's
   <li>level 2</li> //width 100
   <li>level 2</li> //width 50
  </ul>
 </li>
 <li>level 1</li>
<li>
  <ul style="widht:150px;"> //total width children li / add width li's
   <li>level 2</li> //width 100
   <li>level 2</li> //width 50
  </ul>
</li>
</ul>
+1  A: 
var Peek = 0;

$('ul ul').each(function(){    
   $(this).children('li').each(function(i, e){
      if($(e).outerWidth() > Peek)
         Peek = $(e).outerWidth();
   });

   $(this).width(Peek);
   Peek = 0;
});

which would set the sub uls width to the hightest width of the list items.

jAndy
thnx, that works, is it also posible to put de highest width from the current ul? when i have 30 li the peek is very big
Epco