views:

31

answers:

1

this is my code:

<div id="demo1">
    <ul>
        <li>aaa</li>
        <li>
            <ul>
                <li>hhh</li>
                <li>qqqq</li>
            </ul>
        </li>
        <li>qqqqq</li>
        <li>
            <li>lll</li>
            <li>
                <ul>
                    <li>qqwed</li>
                    <li id="1">qqdwdw</li>
                </ul>
            </li>
        </li>
    </ul>
</div>

i have many 'ul' and 'li' elements , now i can get the li '#1',and the div '#demo1'

i want to get all 'li' elements between them ,

how to get it,

i use this code , like next code , but not successful,

$('#1').parent('li')

$('#1').closest('li') 

but , how to make it between the '#demo1' too ?

thanks

+1  A: 

You can use .parentsUntil() to get the parents, then .filter() to get on the <li> elements, like this:

$("#1").parentsUntil("#demo1").filter('li');

I know this is an example, but IDs (in HTML4 at least) can't start with a number either.

Nick Craver
its cool ~.......
zjm1126