how to get all 'li' element from #1 to #demo1 using jquery
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
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.
精彩评论