Jumpy09 Posted November 18, 2011 Share Posted November 18, 2011 Alright so I have this: var tabindex = $("ul#myid").index("li > a.current"); The problem is it isn't quite working the way I want it to. Edit: I do see the problem with this, but I'm still not quite sure how to do what I am aiming for. I know you would do something like $("#myid li").index("#listid");, so I'm still not entirely sure how to get what I want. Take the following code as an example: <ul id="myid"> <li><a href="#blah1">My Link #1</a></li> <li><a href="#blah1">My Link #1</a></li> <li><a href="#blah1" class="current">My Link #1</a></li> <li><a href="#blah1">My Link #1</a></li> <ul> Basically I need to pull the index of the <li> which contains the <a> that has the current class. Basically index need to return 2, but either returns 0 or -1. I am testing it where the current class is on the 3rd to 5th link, so 0 or -1 isn't really an option of what it should spit out. I figure it is because the <a> is in the <li> which would result in 0 to be the index. The issue is I cannot place "current" on the <li>, which of course makes things a bit dumb. From what I thought is it would use the <ul> as a primary parent, then select the <li> of the <a> that contains the current class. Everything in my mind states this is right, or at least should be right.. but obviously it isn't. Any assistance would be greatly appreciated. P.S. I have done some preliminary Googling to find an answer, but I'm kind of on a tight deadline and don't have hours to spend debugging this. I figure it is a rather simple solution, but so far the results from Google have not landed me in the right place to get the answer I need. Kindest Regards, Jumpy09 Link to comment https://forums.phpfreaks.com/topic/251345-finding-the-index-of-a-list-item-which-contains-a-link-element-with-a-class/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.