views:

92

answers:

1

i'm looking for a way to calculate the total width of de level 2 items and put it in the ul. I have looked at some jquery thinks like outerWidth and .lengt but can't figure it out.

thanks in advance

    $('#menu li:has(ul)  ul').each(function()

<ul>
 <li>level 1</li>
 <li>
  <ul style="widht:??;">
   <li>level 2</li>
   <li>level 2</li>
  </ul>
 </li>
 <li>level 1</li>
</ul>
+1  A: 

The width() method of jQuery will give you the calculated width of an element:

$(function(){
  $('#menu li:has("ul")').each(function(){
    alert($(this).width());
  });
});

Get the current computed width for the first element in the set of matched elements.

http://api.jquery.com/width/

alt text

Sarfraz