Assuming this sort of structure:
<li class="page-title">Global</li>
<ul>
<li class="element">Design Elements</li>
<li class="page-title">Alerts</li>
<ul>
<li class="element">Alert 1</li>
<li class="element active">Alert 2</li>
<li class="element">Alert 3</li>
<li class="element">Alert 4</li>
<li class="element">Alert 5</li>
</ul>
</ul>
<li class="page-title">Accounts</li>
<ul>
<li class="element">Accounts Main</li>
</ul>
How can I step through the .element
elements regardless of the nesting structure?
Currently, I'm using .next('.element')
, but at the top or bottom of the set of elements, it starts to return nulls.
I'd like to avoid using some sort of "if this is the last in the set, set up a level and get back in" logic if possible.
EDIT: I should clarify, I'm looking to step up and down a list of these having bound the up and down keys, so I need to be able to select the actual relative next element for whatever's got .active
.
So, assuming we're on Alert 2, a function I've left out runs based on a data-job attribute. We hit the up key, it steps to Alert 1, runs that function again. I'd like to be able to hit the up key again, and it pops up to 'Design Elements'.