[英]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' 我有很多'ul'和'li'元素,现在我可以得到li'#1'和div'#demo1'
i want to get all 'li' elements between them , 我想让它们之间的所有“ li”元素,
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 ? 但是,如何在“#demo1”之间进行匹配呢?
thanks 谢谢
You can use .parentsUntil()
to get the parents, then .filter()
to get on the <li
> elements, like this: 您可以使用.parentsUntil()
获取父对象,然后使用.filter()
获取<li
>元素,如下所示:
$("#1").parentsUntil("#demo1").filter('li');
I know this is an example, but IDs (in HTML4 at least) can't start with a number either. 我知道这是一个示例,但是ID(至少在HTML4中)也不能以数字开头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.