Example is I have a 4 unordered lists on a page:
<div class="UL-GROUP">
<div>
<ul class="UL">
<li><a href="#something1"></a></li>
<li><a href="#something2"></a></li>
<li><a href="#something2"></a></li>
<li><a href="#something3"></a>
<div class="UL-GROUP">
<div>
<ul class="UL">
<li><a href="#something4"></a></li>
<li><a href="#something5"></a></li>
<li><a href="#something6"></a></li>
<li><a href="#something7"></a>
<div class="UL-GROUP">
<div>
<ul class="UL">
<li><a href="#something8"></a></li>
<li><a href="#something9"></a></li>
<li><a href="#something10"></a></li>
<li><a href="#something11"></a></li>
</ul>
<div class="contents">Loads of elements in here</div>
</div>
</div>
</li>
</ul>
<div class="contents">Loads of elements in here</div>
</div>
</div>
</li>
</ul>
<div class="contents">Loads of elements in here</div>
</div>
</div>
<div class="UL-GROUP">
<div>
<ul class="UL">
<li><a href="#something12"></a></li>
<li><a href="#something13"></a></li>
<li><a href="#something14"></a></li>
<li><a href="#something15"></a></li>
</ul>
<div class="contents">Loads of elements in here</div>
</div>
</div>
And I need to iterate over all of them and then track which of the 4 UL's contains a link that matches a specific key, ie "#something4"...
I can't seem to figure out the best way to iterate over these independently and efficiently, while keeping track of which one of the UL's contains the matching key value. At least not without some very ugly chaining using .children (see jQuery code below). So how should I do this with performance in mind?
Note: The nested levels and HTML structure will remain constant, however this is not for something as simple as navigational elements, there will be content mixed in as siblings of the .UL elements which I'm trying also to avoid
JS:
console.log($('.UL-GROUP').children('div').children('.UL').find('a[href*="#something4"]'))
Edit for clarification: I thought of simplifying this, but using the below code I become stuck/unsure as to how I'd track which .UL-GROUP has the key I'm looking for(i.e. with .data):
$('.UL-GROUP > div > ul > li').length