I have a piece of html that, when JQM is done with it, looks like this (simplified):
<div id="servicesList">
<div id="servicesHeader">Services</div>
<ul data-role="listview" class="ui-listview">
<li id="Serv1" class="serviceLink">Service 1</li>
</ul>
<ul data-role="listview" class="ui-listview">
<li id="Serv2" class="serviceLink">Service 2</li>
</ul>
</div>
This code is dynamically generated from another piece of script.
Each of the Services has a click event attached to it that pulls in some more data dynamically. Ideally, I'd like to be able to reference the index of the Service at the time that it's clicked on. Here's my current code:
$('.serviceLink').click(function() {
var index = $(this).closest("ul").index();
servAnimate(index);
});
Obviously, this doesn't work as the array of objects pulled in includes the servicesHeader div. How do I go about getting only the array of parent ul's? Essentially, when the user clicks on Service 1, the index returned should be a 0, not a 1. Right now, index 0 references the servicesHeader div.
I've also tried this:
$(this).closest("ul").filter("ul").index();
Any help would be appreciated!
EDIT: I should have specified that the HTML is being generated by a script from another developer. It may change, it may stay the same. The only assurance I have so far is that the ULs will stay on the same level and will have the class serviceLink.
So again, how do I get the index of the parent ULs only regardless of what other sibling elements exist?