How can I recurse up a DOM tree?

Posted by smartdirt on Stack Overflow See other posts from Stack Overflow or by smartdirt
Published on 2010-12-28T17:31:47Z Indexed on 2010/12/28 21:53 UTC
Read the original article Hit count: 268

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about dom