How can I recurse up a DOM tree?
- by smartdirt
So I have a series of nested ul elements as part of a tree like below:
<ul>
<li>
<ul>
<li>1.1</li>
<li>1.2</li>
</ul>
<ul>
<li>2.1</li>
<li>
<ul>
<li>2.2</li>
</ul>
</li>
</ul>
<ul>
<li>3.1</li>
<li>3.2</li>
</ul>
</li>
</ul>
Let's say when 3.1 is the selected node and when the user clicks previous the selected node should then be 2.2. The bad news is that there could be any number of levels deep. How can I find the previous node (li) in relationship to the currently selected node using jquery?