index() not returning index of object

index() not returning index of object

This is driving me insane! I am trying to get the index of a li with a specific class. I know I'm selecting the right object because I can apply a CSS class to it (eg change border colour) but when I try to get the index it returns -1. But I know the object exists as I can alter it. :-s

So, any ideas what I might be doing wrong?

  1. jQuery(document).ready(function() {
  2. var active = $("#tertiarynavigation .bordered").get(0);
  3. var num = $("#tertiarynavigation li").index(active);
  4. alert("Index: " + num);
  5. });



  1. <ul id="tertiarynavigation">
  2. <li><a href="/royalhospitalchelsea"><img src="con_03_01.jpg" alt="Royal Hospital Chelsea, London" /></a></li>
  3. <li><a href="/grosvenorplacekamizonocho"><img src="res_02_01.jpg" alt="Grosvenor Place Kamizono-cho, Tokyo" /></a></li>
  4. <li><a href="/manresaroad"><img src="res_04_01.jpg" alt="Manresa Road, London" /></a></li>
  5. <li><a href="/pembridgegardens"><img src="res_05_01.jpg" alt="Pembridge Gardens, London" /></a></li>
  6. <li><a href="/dukeofyorksquarephase3"><img src="res_06_01.jpg" alt="Duke of York Square, London, Phase lll" /></a></li>
  7. <li><a href="/brindisihouse"><img src="res_07_01.jpg" alt="Brindisi House, Italy" /></a></li>
  8. <li><a href="/grosvenorplacehongkong"><img src="res_08_01.jpg" alt="Grosvenor Place, Hong Kong" /></a></li>
  9. <li><a href="/harrowwweald"><img src="ud_06_01.jpg" alt="Harrow Weald, London" /></a></li>
  10. <li><a href="/basilstreet"><img src="basilstreet_01.jpg" alt="Basil Street Residential, London" /></a></li>
  11. <li><a href="/310grosvenorcrescent"><img src="con_02_01.jpg" alt="3-10 Grosvenor Crescent, London" /></a></li>
  12. <li><a href="/19cadogangardens"><img src="con_04_01.jpg" alt="19 Cadogan Gardens, London" /></a></li>
  13. <li><a href="/lansdownecrescent"><img src="res_03_01.jpg" alt="Lansdowne Crescent, London" /></a></li>
  14. <li><a href="/westminsterterrace"><img src="res_09_01.jpg" alt="The Westminster Terrace" /></a></li>
  15. <li><a href="/kennedyroadhongkong"><img src="res_10_01.jpg" alt="Kennedy Road, Hong Kong" /></a></li>

  16. <li><img src="res_12_01.jpg" alt="203 Kings Road, London" title="203 Kings Road, London" class="bordered" /></li>

  17. <li><a href="/mountkelletthongkong"><img src="res_11_01.jpg" alt="Mount Kellett, Hong Kong" /></a></li>
  18. <li><a href="/21wappinglane"><img src="res_13_01.jpg" alt="21 Wapping Lane, London" /></a></li>
  19. <li><a href="/tianjinchina"><img src="mu_02_01.jpg" alt="Tianjin, China" /></a></li>
  20. <li><a href="/ecotower"><img src="sus_03_01.jpg" alt="Eco Tower, London" /></a></li>
  21. </ul>

Thanks,


M