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?
- jQuery(document).ready(function() {
- var active = $("#tertiarynavigation .bordered").get(0);
- var num = $("#tertiarynavigation li").index(active);
- alert("Index: " + num);
- });
- <ul id="tertiarynavigation">
- <li><a href="/royalhospitalchelsea"><img src="con_03_01.jpg" alt="Royal Hospital Chelsea, London" /></a></li>
- <li><a href="/grosvenorplacekamizonocho"><img src="res_02_01.jpg" alt="Grosvenor Place Kamizono-cho, Tokyo" /></a></li>
- <li><a href="/manresaroad"><img src="res_04_01.jpg" alt="Manresa Road, London" /></a></li>
- <li><a href="/pembridgegardens"><img src="res_05_01.jpg" alt="Pembridge Gardens, London" /></a></li>
- <li><a href="/dukeofyorksquarephase3"><img src="res_06_01.jpg" alt="Duke of York Square, London, Phase lll" /></a></li>
- <li><a href="/brindisihouse"><img src="res_07_01.jpg" alt="Brindisi House, Italy" /></a></li>
- <li><a href="/grosvenorplacehongkong"><img src="res_08_01.jpg" alt="Grosvenor Place, Hong Kong" /></a></li>
- <li><a href="/harrowwweald"><img src="ud_06_01.jpg" alt="Harrow Weald, London" /></a></li>
- <li><a href="/basilstreet"><img src="basilstreet_01.jpg" alt="Basil Street Residential, London" /></a></li>
- <li><a href="/310grosvenorcrescent"><img src="con_02_01.jpg" alt="3-10 Grosvenor Crescent, London" /></a></li>
- <li><a href="/19cadogangardens"><img src="con_04_01.jpg" alt="19 Cadogan Gardens, London" /></a></li>
- <li><a href="/lansdownecrescent"><img src="res_03_01.jpg" alt="Lansdowne Crescent, London" /></a></li>
- <li><a href="/westminsterterrace"><img src="res_09_01.jpg" alt="The Westminster Terrace" /></a></li>
- <li><a href="/kennedyroadhongkong"><img src="res_10_01.jpg" alt="Kennedy Road, Hong Kong" /></a></li>
- <li><img src="res_12_01.jpg" alt="203 Kings Road, London" title="203 Kings Road, London" class="bordered" /></li>
- <li><a href="/mountkelletthongkong"><img src="res_11_01.jpg" alt="Mount Kellett, Hong Kong" /></a></li>
- <li><a href="/21wappinglane"><img src="res_13_01.jpg" alt="21 Wapping Lane, London" /></a></li>
- <li><a href="/tianjinchina"><img src="mu_02_01.jpg" alt="Tianjin, China" /></a></li>
- <li><a href="/ecotower"><img src="sus_03_01.jpg" alt="Eco Tower, London" /></a></li>
- </ul>
Thanks,
M