finding with of a specific child using children

finding with of a specific child using children

Hi,

I'm trying to obtain the width of a specific element without using it's id

Using this markup:

  1. <ul id="nav">
  2.                     <li id="1"><a href="#">1----</a>
  3.                         <ul>
  4.                             <li id="1a"><a href="#">1a----</a></li>
  5.                             <li id="1b"><a href="#">1b----</a></li>
  6.                         </ul>
  7.                     </li>
  8.                     <li id="2"><a href="#">2----</a></li>
  9.                     <li id="3"><a href="#">3----</a></li>
  10.                     <li id="4"><a>4----</a>
  11.                         <ul>
  12.                             <li id="4a"><a href="#">4a----</a></li>
  13.                             <li id="4b"><a href="#">4b----</a></li>
  14.                         </ul>
  15.                     </li>
  16.                 </ul>

  17. <div id="theDiv">
  18. <p id="x"></p>
  19. <p id="y"></p>
  20. </div>
and this jquery:

  1. var x = $('#nav li ul').children()[0];
  2. var y = $('#nav li ul').children()[0].width();
  3. $('#theDiv #x').append(x);
  4. $('#theDiv #y').append(y);
It returns x fine, in this case the element 1a, however it simply return 0 for the y

Can anybody tell me where I'm going wrong

Thanks in advance